Felix Grund
Instructor @ UBC
Devising test cases given a (clear) EFFECTS clause (knowing what to test)
Using combinations of inputs and outputs to determine what tests to write
Write Tests
Run Tests
FAIL
Implement
PASS
// REQUIRES: dx > 0
// MODIFIES: this
// EFFECTS: adds dx to xcoord
public void move(int dx) {…}// MODIFIES: this
// EFFECTS: inserts the integer into the set, unless it's
// already there, in which case it does nothing.
// if the number is 0 it returns "that's nothing!"
// if the number is <0 it returns "that's negative!"
// if the number is >0 it returns "that's positive!"
public String insert(Integer num) { }-1 0 1
-∞
+∞
-10
+10
-10
testInsertNegativetestInsertNegativeAtUpperBoundarytestInsertZerotestInsertPositivetestInsertPositiveAtLowerBoundarypublic class Oven {
private int temperature;
// EFFECTS: constructs an oven
// whose temperature is 65F
public Oven() {
// stub
}
// REQUIRES: 180 <= degrees <= 500
// MODIFIES: this
// EFFECTS: heats oven to degrees Fahrenheit
public void preheatTo(int degrees) {
// stub
}
}public class Oven {
private int temperature;
// EFFECTS: constructs an oven
// whose temperature is 65F
public Oven() {
// stub
}
// REQUIRES: 180 <= degrees <= 500
// MODIFIES: this
// EFFECTS: heats oven to degrees Fahrenheit
public void preheatTo(int degrees) {
// stub
}
}public class Oven {
private int temperature;
// EFFECTS: constructs an oven
// whose temperature is 65F
public Oven() {
// stub
}
// REQUIRES: 180 <= degrees <= 500
// MODIFIES: this
// EFFECTS: heats oven to degrees Fahrenheit
public void preheatTo(int degrees) {
// stub
}
}public class Truck {
// MODIFIES: this
// EFFECTS: sets the status of
// the truck to 'driving'
public void drive() { ... }
// EFFECTS: returns true if the
// truck has a status of 'driving'
public boolean isDriving() { ... }
// MODIFIES: this
// EFFECTS: sets the status of
// the truck to 'parked'
public void park() { ... }
// ...
}public class TruckTest {
}@Test
public void driveTest() {
}@Test
public void parkTest() { ... }private Truck truck;@BeforeEach
public void setup() {
this.truck = new Truck();
}this.truck.drive();
assertTrue(this.truck.isDriving());By Felix Grund