Public:Automatic tests
From YaddaWiki
Contents |
Tests
Tests are significant part of the programming effort. They not only have to be written, but also be maintained with the rest of the code.
We write a unit test for each public and package private method with the exception of simple getters/ setters and equals/ toString methods. You are not allowed to push to the repository the code that does not contain unit test methods for all the classes.
We write an integration test for each use case or specific functionality.
Testing library
Due to its readability and ease of learn we have decided to use [https://assertj.github.io/doc/ AssertJ) as a testing framework.
Separation of the unit and integration tests
Unit tests are tests which do not require specific environment to be run and may be run during each compilation.
Integration tests require specific environment and are not expected to be run during each compilation.
Because of that, we usually separate the unit/integration tests logically so they can be run separately.
Unit test location
All unit tests are located within the standard maven directory structure, in:
src/test/java
All resources required by tests, but not required by the executable code are stored in:
src/test/resources
Unit tests are tests of specific classes, so:
- a test class should be in the same package as the tested class
- the name of the test class should be made of the name of the tested class suffixed with `Test`. For example if the tested class name was StringConverter, its test class would be StringConverterTest
Test method naming
All testing methods must have clear and significant names. It is recommended that each test method has name methodName__conditionsToTest, for the method formatString() it would be for example:
formatString__nullValue() formatString__onlyNumbers() formatString__tooManyPlaceholders()