Unit testing

The essence of unit testing is to break an application down into its smallest functional blocks (units) and then test each unit with real-world scenarios within the scope of the initiative. For example, take a simple method that takes two signed integers and adds them together:

int add(intx, int y);

Some example scenarios can be as listed:

  • Adding two positive numbers
  • Adding two negative numbers
  • Adding two zeroes
  • Adding one positive and one negative number
  • Adding zero and a positive number
  • Adding zero and a negative number

We can write a test for each of these scenarios and then every time our code base changes (any code, not just our add() method), these tests can be executed to ensure that the code still behaves as expected. ...

Get Learn Qt 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.