Test failures happen when

The system under test has a problem or is incomplete.

The test itself is flawed.

Make test complete and concise

Complete (起承轉合)

Test body contains all of the information a reader needs to understand it arrives at its results.

Concise (Show intention)

Test contains no other distracting or irrelevant information.

Example

Bad example

Screen Shot 2022-05-02 at 3.35.23 PM.png

Problem:

The test is passing a lot of irrelevant information into the constructor, and the actual important parts of the test are hidden inside of a helper method.

Good example

Untitled

Solution:

The test can be made more complete by clarifying the inputs of the helper method

Using another helper to hide the irrelevant details of constructing the calculator.

newCalculator hides irrelevant details.