Broad Stateful Testing

Take a look at the broad stateful tests of the application and how they test the system.

Getting started

We’ll start with a very wide scan of the system to make sure the basic stuff works. This will check for simple API misunderstandings, errors that type analysis couldn’t reveal, or issues with configuration or the basic test setup.

The property

Let’s start off by adding the actual property declaration to our module. Take a look at the property in the code provided below in the test/prop_bookstore.erl file.

In the property, we’ll make use of the ?SETUP macro to boot the bookstore OTP application once for all the tests, ensuring that all libraries and dependencies are in place. We’ll then call the bookstore:setup/0 and bookstore:teardown/0 functions on each iteration to get rid of the database table and its state between each test so that the execution is clean.

We can now start on the model.

The model

For the model, we’ll do nothing but function calls to keep employing the skills we learned during broad testing.

The model is defined in the code provided below in the test/prop_bookstore.erl file from line 21 to line 48.

The command/1 function is the only significant function. For now, the other functions do not affect the testing. The precondition and postcondition states are always true. As for the next_state, it has no effect on the working of the application.

Running the tests

Let’s run the tests that we have and see what we get.

Get hands-on with 1400+ tech skills courses.