Firstly let’s agree that “unit test” is often used to cover all automated tests a programmer writes, and that it is pointless to debate what each test should be called….
I have worked on a system where the software took a lot of inputs and worked out a “solution” that had to fulfil some constraints, while optimizing other numbers. There were no right answers, so the software just had to give a reasonable answer.
It did this by using lots of random numbers to get a starting point, then using a “hill climber” to improve the result. This was run many times, picking the best result. A random number generator can be seeded, so that it always gives the same numbers out in the same order, hence if the test set a seed, we know that the result would be the same on each run.
We had lots of tests that did the above, and checked that the results were the same, this told us that we had not changed what that part of the system did by mistake while refactoring etc. It did not tell us anything about the correctness of what that part of the system did.
These tests were costly to maintain, as any change to the optimising code would break the tests, but they also found some bugs in the much larger code that pre-processed the data, and post-processed the results.
As we “mocked” the database, you could call these tests “unit tests”, but the “unit” was rather large.
Often when you are working on a system with no tests, you do something like the above, so that you can confirm your refactoring don’t change the output; hopefully better tests are written for new code!
1, 2, 3
are 3D array indices where you previously stored the value17
, then I think this test would be dandy (as long as you have some negative tests as well). But if it's the result of a calculation, you should make sure that anyone reading this test will understand whyfoo(1, 2, 3)
should be17
, and magic numbers probably won't achieve that goal.const int TWO = 2;
is even worse than just using2
. It's conforming to wording of the rule with intent to violate it's spirit.foo
, it would not mean anything, and so the parameters. But in reality, I am pretty sure the function does not have that name, and the parameters don't have namesbar1
,bar2
, andbar3
. Make a more realistic example where the names have a meaning, then it makes much more sense to discuss if the test data values need a name, too.