Testing
This chapter covers writing JUnit tests for an ADT, organizing them as one contract suite that runs against every implementation, and test-first development.
After reading this chapter, you should be able to:
- Explain why correctness is measured against an ADT contract rather than against the code
- Explain why passing tests are evidence of correctness rather than proof
- Write focused JUnit tests that check one behavior each, are named by scenario, and start from a fresh
@BeforeEachfixture - Test that a method throws the exception its contract names, using the try / fail / catch idiom
- Write a contract test suite once, as an abstract class with a factory method, and run it against every implementation
- Choose edge cases for a list from its contract
- Explain how writing tests before the implementation turns the contract into an executable specification
You can download the accompanying code for this chapter: starter and solution.