To run the tests;
mvn test
To generate a test coverage report;
mvn test jacoco:report
The generated report will be in "target/site/jacoco/index.html".
Test coverage is 100% - the only untested code is GildedRoseExpandsApplication#main(String[] args)
, which is only one line long (and not easily unit tested).
There are several integration tests in /src/test/java/com/miw/gildedroseexpands/integrationtests.
The main test classes are;
- IntegrationTestBase.java - this is a base class for the integration tests that setup the spring injection, test data, and TestRestTemplate.
- InventoryIntegrationTests - This tests buying items and looking at the inventory (admin).
- SimpleItemIntegrationTests - This tests looking at items (including surge pricing).
- SecurityIntegrationTests - This tests that security is being restricted (i.e. need to be logged on to buy).
These all use the TestRestTemplate
to make real request to the system. Test data is pre-populated.
There are several spring tests -
- item - tests associated with the ItemEntity. This includes ensuring viewing and buying sends events (see arch) and the support services are working correctly.
- inventory - tests associated with Inventory (i.e. allocating inventory)
- surgetracking - tests recording, purging, and counting views associated with viewing item (determines if a price should be surged).
These will test the Repository, Controller, and any Services. They typically mock (mockito) dependencies to make sure that they are being correctly called.
There are a set of simple unit tests in trivialobjecttests.
These tests are for objects with little-to-no behaviour (i.e. JPA Entities, ViewModel Objects) and some very simple functionality (i.e. TimeTests).