Answer the question
In order to leave comments, you need to log in
TDD, many Asserts
Hello everyone, a question: in books and articles on the Internet on TDD they say that you need to start with assertions and preferably with one and write as little as possible for one test. Having learned such an example, I am developing a class that produces dates based on the given parameters (weekly schedule). According to TDD, I start with writing a test and with an assertion to display the required dates.
//Assert
Assert.AreEqual(result[0].Start, DateTime.Parse("04.12.13 08:00:00"));
Assert.AreEqual(result[0].Finish, DateTime.Parse("06.12.13 00:00:00"));
Assert.AreEqual(result[1].Start, DateTime.Parse("11.12.13 08:00:00"));
Assert.AreEqual(result[1].Finish, DateTime.Parse("13.12.13 00:00:00"));
//..... итд еще 100500 асcертов на два месяца
Answer the question
In order to leave comments, you need to log in
Use Incoming Parameters
NUnit Example
[TestCase(0, "04.12.13 08:00:00", "06.12.13 00:00:00")]
[TestCase(1, "04.12.13 08:00:00", "06.12.13 00:00:00")]
public void Test123(int i, DateTime s, DateTime e)
{
Assert.That(result[i].Start, Is.EqualTo(DateTime.Parse(s)));
Assert.That(result[i].Finish,Is.EqualTo( DateTime.Parse(e)));
}
usually the data is organized into an array, bypassed and asserted. alas, I am not familiar with unit testing in .NET. But if it is a large number of assertions that confuses you, then there is nothing to worry about. You can then refactor your tests so that they do not make unnecessary assertions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question