Unit testing

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

Figure 291. Recommended reading Slide presentation

Figure 292. 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 293. 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 294. Unit test principle Slide presentation

Figure 295. Test driven development Slide presentation

First write tests, then implement.


Figure 296. 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.