To consolidate the knowledge that I have been acquiring on the subject, I created this practical example of an automated unit/mutation testing framework built with Jest and StrykerJs.
I created a function to validate whether the user can drive, based on age and a valid driver's license. I consider, for instance, that a person can get a driver's license at the age of 18 and beyond.
I used the equivalence partitioning and boundary value analysis to devise the basic test cases:
- Age of 17
- Age of 18 and no valid driver's license
- Age of 18 and a valid driver's license
- Age of 19 and no valid driver's license
- Age of 19 and a valid driver's license
The project is already configured to run the test coverage.
Tools:
Run npm i to install the dev dependencies.
To run the tests via the command line of all test classes in the project:
npm run test
To run the tests via the command line of all test classes in the project:
npm run mutation
Running the tests make the application generates a test coverage report