Unit testing

Some parts of the examination require implementing methods adhering to a given specification. Consider an example:

Figure 299. Recommended reading Slide presentation

Figure 300. Test categories Slide presentation
  • Unit test: Test individual methods, classes and packages in isolation.

  • Integration Test: Test a group of associated components/classes.

  • Acceptance / Functional Test: Operate on a fully integrated system, testing against the user interface.

  • Regression Test: Ensure system integrity after (implementation) change.

  • Load test: Responsiveness vs. system load.

Figure 301. Example: Computing prime numbers Slide presentation

Informal problem specification:

A prime number is a whole number greater than 1 whose only factors are 1 and itself.

Sample values: 2, 3, 5, 7, 11, 13, 17, 23, ...

Figure 302. Unit test principle Slide presentation

Figure 303. Test driven development Slide presentation

First write tests, then implement.

Figure 304. Steps in Unit Testing Slide presentation
  1. Specify but not yet implement classes / methods.

  2. Write skeleton (dummy) implementations.

  3. Write corresponding unit tests.

  4. Implement skeleton.

  5. Test your implementation.