Consider the following code (from a requirement that says 3 is special for some reason):
bool IsSpecial(int value)
if (value == 3)
return true
else
return false
I would use unit test for several functions: one of them was called TEST (3IsSpecial), which claims that when passing 3, the function returns true, and the other, which passes some random value other than 3, and claims that the function returns false .
When the requirement changes and say that now it becomes 3 and 20 are special, I would write another test that checks that when called from 20, this function also returns true. This test will fail, and then I will go over and update the if condition in the function.
Now, what if in my team there are people who do not believe in unit testing, and they make this change. They will directly jump over and modify the code, since my second unit test may not test 20 (this may be a random int choice or have some other int hardcoded). Now my tests are not synchronized with the code. How can I make sure that when changing the code, some unit test or others do not work?
I could be doing something grossly wrong, so any other methods to get around this are also welcome.
source
share