10. @Test
public void testSum3() {
// When I add two numbers I expect their sum
for (int i = 0; i < 100; i++) {
int x = randomInt();
int y = randomInt();
assertThat(sum(x, y), equalTo(x + y));
}
}
11. @Test
public void testSum3() {
// When I add two numbers I expect their sum
for (int i = 0; i < 100; i++) {
int x = randomInt();
int y = randomInt();
assertThat(sum(x, y), equalTo(x + y));
}
}
12. @Test
public void testSumUsingCommutativityProperty() {
// Changing the order of arguments
// shouldn’t change their sum
for (int i = 0; i < 100; i++) {
int x = randomInt();
int y = randomInt();
assertThat(sum(x, y), equalTo(sum(y, x)));
}
}
14. @Test
// `x + 2` is the same as `x + 1 + 1`
public void testSumWithAdditiveProperty() {
for (int i = 0; i < 100; i++) {
int x = randomInt();
int result1 = sum(sum(x , 1), 1);
int result2 = sum(x, 2);
assertEquals(result1, result2);
}
}
22. John Hughes - Testing the Hard Stuff and Staying Sane
23.
24. Benefits
• Less time spent writing test code
- One property replaces many tests
• Better testing
- Lots of combinations you’d never test by hand
• Less time spent on diagnosis
- Failures minimized automatically
25. 3,000 pages of specifications
20,000 lines of QuickCheck
1,000,000 LoC from 6 suppliers
200 bugs
100 bugs in the standard
33. How to handle state?
• Generate actions changing the state
• Apply each action to the state, if possible
• After each application, verify the model
35. Spark Proxy on DataFrame
API
• Generate random DataReadRequest
• Execute request with RDD-based code
• Execute same request with DataFrame based code
• Compare the results
36. SDK
• Send START_VIS
• Generate random request, change metric, group-
by, filter, sort, etc
• Validate responses based on the test model
• Send STOP_VIS
37. • QuickCheck
• Testing Telecoms Software with Quviq QuickCheck
• Testing the hard stuff and staying sane
• The Mysteries of Dropbox
• Jepsen IV: Hope Springs Eternal
• Java Examples from this talk