For some time I neglected unit testing. I wrote unit tests, but they were pretty poor. I am currently reading The Art of Unit Testing to bring it to zero.
If I have an interface, for example:
public interface INotificationService { void AddError(string _error); void AddIssue(string _issue); IEnumerable<string> FetchErrors(); IEnumerable<string> FetchIssues(); }
A specific implementation of this interface contains:
private readonly ICollection<Message> messages;
Adding an error or problem creates a new message with an enumeration indicating its type and adds it to the collection. Calling FetchErrors () / FetchIssues () returns messages of this type from the collection.
Will the following test be performed:
[Test] public void FetchErrors_LoggingEnabledAddErrorFetchErrors_ReturnsError() { notificationService = new NotificationService(); notificationService.AddError("A new error"); Assert.AreEqual(new []{"A new error"}, notificationService.FetchErrors()); }
My concern is that I first call AddError () and then test the result of FetchErrors (). Therefore, I call two functions. This is not true?
Should I make the collection publicly available and explicitly state that it contains a message of the appropriate type containing a registered error message?
What would be the best practice in this scenario?
c # unit-testing nunit
Chris w
source share