Index

Overview


Automated unit testing is writing code to test code. In other words, using the computer to find bugs.

Iterative dev: Code, test, code, test, ...

Bang for the Buck

Nothing has better bang for the buck than test code as this short video demonstrates:

Two Lines of Code Finds Three Blocker Bugs

Test code is also our best friend for finding sneaky subtle bugs.

Example Test Code



JUnit


JUnit is a popular testing framework. More here...

The Handy Ternary Operator


Remember the ternay operator
?:


It's quite handy for testing.

Example:

out.println("testInflateLakes -- " + (actual.equals(expected) ? "PASSED" : "FAILED"));


Naming Test Methods


The reference here is presented only as food for thought.

The basic idea is just try to use clear method names, as always.


junit unit test test method naming:


UnitOfWork StateUnderTest ExpectedBehavior
test_methodName_withCertainState_shouldDoSomething

test_noArgsConstructor_initialization_zeroed