14 Advanced unit testing

If code depends on called code, how do you know where an error is from?
Test doubles—stand in [stunt doubles?]
(also called stub testing)
a double/stub should report how it was called.
If a return value is needed, can be a fake one.
Use a test double when the code you are testing uses other code.
Once you have verified it calls the other code correctly, 
and does its own logic correxctly, given the behavior of the double,
THEN you can repeat tests while actually calling the code!

ALWAYS test the code being called completely before testing the calling code!

If a method gereates and uses objects internally, cannot do a test double
(If needed, re-write so that it calls an external method that can be tested)

stub: a function that returns an artificial (but usable) value

Assertions are great, but this can all be done with PRINT statements.
(Manually verify that the print messages are correct.)

 To verify how many times something is called, the stub/double can maintain a counter.

fake—scaled down version of real object or method

setup
teardown

unit testing
test more common use cases first
safety-critical: test for failure detection first
make sure test reports WHAT failed (replication)

unit tests should not depend on wht order called in
(Junit calls test in a random order)
intermittent fails: look for hidden dependancies/side effects

some testing systems can run tests in parallel

You might deal with legacy code.
Consider touching it up each time you use it.

Wrapper functions are used to call an existing function;
either differently, or with error checking, etc.

Consider buidling a wrapper around code that is difficult to test

code coverage; verifying that code was called
(Not the same as verifying it returned the correct answer)

When you are [unit] testing, you should remember to perform some manual testing, integration testing, and depending upon your needs, other kinds of testing such as security testing or performance testing.
Relying heavily on one particular kind of testing is a recipe for missing important defects.