I would avoid to keep multiple unit tests that check the same code, because in the future:
- If you'll intentionally change the
check
function in a way that break your tests, you'll have to change 2 tests instead of one. - If you unintentionally break the
check
, you'll get two failures: one referring tofoo
and one referring tobar
, and it could not be obvious that what is broken is thecheck
function.
So, I would keep only one set of tests, explicitly named as tests for the check
function, and even better, don't use function of your program to test them (not foo
neither bar
in your example) but use a fake function used only for tests purposes.
In this way, you can in future alter foo
or bar
to use, e.g., a check2 function without break tests of check function
This is, according to me, the best theoretical approach to go, but be pragmatic: don't try to follow this way if you don't expect to use the check
function in a great portion of your code: your target has to have the main program running smoothly, not a beautiful set of tests...