Public:Automatic tests

From YaddaWiki

(Difference between revisions)
Jump to: navigation, search
(Tests)
 
(13 intermediate revisions not shown)
Line 1: Line 1:
=Tests=
=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. Therefore the following rules apply:
+
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 use we have decided to use [https://assertj.github.io/doc/ AssertJ] as a testing framework.
==Separation of the unit and integration tests==
==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.  
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.
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==
==Unit test location==
Line 18: Line 28:
  src/test/resources
  src/test/resources
-
Unit tests are the tests for classes, so:
+
Unit tests are tests of specific classes, so:
-
* test class for a given class should be in the same package as the tested class
+
* 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'''
* 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==
==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:
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__null_value()
  formatString__null_value()
 +
formatString__onlyNumbers()
  formatString__only_numbers()
  formatString__only_numbers()
 +
formatString__tooManyPlaceholders()
  formatString__too_many_placeholders()
  formatString__too_many_placeholders()

Latest revision as of 08:59, 14 June 2022

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 use we have decided to use 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__null_value()
formatString__onlyNumbers()
formatString__only_numbers()
formatString__tooManyPlaceholders()
formatString__too_many_placeholders()
Personal tools