I'm a very new newcomer to TDD , and I just dont get this.
what would a good failing test look like for:
"Int Sum(int a, int b) : returns the sum of the two numbers"
sorry for being a newb!
cheers!
It doesn't matter if you're a newb or pro, if Roy shows a bad or inappropriate example, he needs to follow up with a good example to complete his article.
Thanks
no reply?
i guess roy must be a new to tdd also........
Gee, amazing banter going on.
In any case, a valid reality test might look like this (see if you can spot the differences):
[Test]
Public void Sum_AddsOneAndTwo()
{
int result = Sum(1,2);
Assert.AreEqual(3, result, “bad sum of 1 and 2”);
}
[Test]
Public void Sum_AddsThreeAndTwo()
{
int result = Sum(3,2);
Assert.AreEqual(5, result, “bad sum of 3 and 2”);
}
And to make the test fail, the actual method you're testing should first return an incorrect answer.
int Sum(int a, int b)
{
return 0;
}
Test fails
Now fix the code:
int Sum(int a, int b)
{
return a + b;
}
Test passes
actually:
Now fix the code:
int Sum(int a, int b)
{
return 3;
}
then write another test that provces you're sending a hard coded value (see my post on testing angles earlier)