Chapter 27Value Patterns

Patterns in This Chapter

Literal Value 714

Derived Value 718

Generated Value 723

Dummy Object 728

Literal Value

Also known as

Hard-Coded Value, Constant Value

How do we specify the values to be used in tests?

We use literal constants for object attributes and assertions.

BigDecimal  expectedTotal  =  new  BigDecimal("99.95");

The values we use for the attributes of objects in our test fixture and the expected outcome of our test are often related to one another in a way that is defined in the requirements. Getting these values—and, in particular, the relationship between the pre-conditions and the post-conditions—right is crucial because it drives the correct behavior into the SUT.

Literal Values are a popular way to ...

Get xUnit Test Patterns: Refactoring Test Code now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.