Skip to content

Companion repository for "How to Make Calculation Tests Simpler and More Expressive with These New Refactorings" article

License

Notifications You must be signed in to change notification settings

ceddlyburge/unit-testing-calculations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unit testing complicated calculations

Build status

This repository contains the example code for a blog post on unit testing complicated calculations.

It is good to make tests as descriptive as possible, to achieve Tests as Documentation. Including the calculations in the test is a big part of this, and avoids the Hard Coded Test Data smell.

This example code has an initial naive test, which is around 30 lines long. It doesn't include the calculations, and introducing them would make the test even longer and more complicated, so would be hard to justify.

The blog describes a series of refactorings, which build on the existing test refactorings from XUnit Test Patterns.

The refactorings reduce the number of paths through the code and simplify the test. This means that less tests are needed, and that the tests become small and simple enough to include the calculations.

Extract Calculation From Loop

Introduce Mockable Abstractions

Test Conditional Branches In Isolation

Test Values In Isolation

Test Partial Values in Isolation

Introduce Blackboard Pattern

About

Companion repository for "How to Make Calculation Tests Simpler and More Expressive with These New Refactorings" article

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published