K
K
kid-programmer2013-12-25 00:28:29
C++ / C#
kid-programmer, 2013-12-25 00:28:29

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ертов на два месяца

Tell me, please, is something wrong or everything is fine? What is the right way to approach this task, where is the right place to start?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Osadchuk, 2013-12-25
@kid-programmer

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)));                 
}

* corrected the example so that it really was from NUnit

S
Sergey, 2013-12-25
Protko @Fesor

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.

Y
Yuri, 2013-12-25
@Gilga

Develop and test every single function. Calling the same function 100500 times does nothing.
I assume you have a method at the input of some date and some parameter, at the output we get the date, logically, it should not be earlier than the original date.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question