Data Injection

The simplest form of override encapsulation allows you to inject simple data into the software under test. No matter how much you model actors in your system as objects, attributes are still the fundamental building blocks. Let’s start by using encapsulation and overriding with basic data types as shown in Listing 8-1.

Listing 8-1: Code under test for basic data type injection

public class TemperatureWatcher {  public static final double REALLY_COLD_F = 0.0;  public static final double REALLY_HOT_F = 100.0;  public static final String REALLY_COLD_RESPONSE =      "Really cold!";  public static final String REALLY_HOT_RESPONSE =      "Really hot!";  public static final String NORMAL_RESPONSE = "Okay"; ...

Get Quality Code: Software Testing Principles, Practices, and Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.