Key Points

o    Increased confidence in code correctness 

o    Increased ability to refractor 

o    Regression Testing - confidence that recent changes have not broken existing functionality

Javadoc for a Tire class.

Setting a Method Result

Failing Tests

Finding the Bug

Passed All Test Cases

Class Exercise

Power Point Presentation


Two short exam questions:

Question #1: In order to optimally unit test a program with 3 classes total at least how many companion classes are required?

Solution #1: Three, since each class would need its own companion class to test its methods.

Question #2: If you were hired at a company and asked to improve an existing code base list three reasons why existing JUnit Tests would make your job easier?

Solution #2:

1.      Test cases exist so confidence can be increased that code modifications are correct.

2.      Refactoring or completely rewriting an existing method involves less risk. Since unit tests can verify the method modified and entire program still pass existing test cases.

3.      New features can be added with reduced risk since existing code can be verified for compatibility issues.


References: