Album Cover

Microtesting Java

Close Preview
Code being tested never knows it is being tested.
A microtest is only valid if the code being tested behaves exactly as it does in production.
People are sometimes tempted to include an if statement to check if their program is running in the test environment vs the real environment.
When that happens, there's a good chance that your microtests are testing fake code instead of real code.
PseudocodeCommentary
if ("test" in path)Inspecting your environment to spot "test mode" is bad mojo. Don't do it.
if (system.clock is fake)Checking for test artifacts in your program is out, too.
if (TESTING)A test flag is at least explicit, but still no.
#ifdef TESTINGConditional compiles? Iffy. Make sure your microtests are testing REAL code.
call_function(fake)Passing a fake to a function is fine, provided that the function doesn't know it's working with a fake. After all, you are micro-testing the function, not the system!
Friends don't let friends test fake code!
(Reading...)
| Tweet...
Page rating: | Rate this Page