The Standard Microtest
The Fidelity Rule
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.
Pseudocode | Commentary |
---|---|
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 TESTING | Conditional 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...)
Formatting Hints:
To format... | use this markup: |
---|---|
source code | {source:lang=java|lineNumbers=false}...{source} (Supported languages: java, cpp, csharp, c, python.) |
bold text | __some text__ |
italicized text | ~~some text~~ |
underlined text | @@some text@@ |
a method or class name | ``myMethod(...)`` |