Public:Automatic tests

From YaddaWiki

(Difference between revisions)
Jump to: navigation, search
 
(15 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 to be maintained with rest of the code as well. Therefore 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==
-
All unit tests are located within standard maven directory structure, in:
+
 
 +
All unit tests are located within the standard maven directory structure, in:
 +
 
  src/test/java
  src/test/java
 +
All resources required by tests, but not required by the executable code are stored in:
All resources required by tests, but not required by the executable code are stored in:
 +
  src/test/resources
  src/test/resources
-
Unit tests are tests for the classes, so:
+
 
-
* tests referring to the custom class are in the same package as tested class
+
Unit tests are tests of specific classes, so:
-
* tests for the class are in class named '''ClassNameTest''', e.g. for '''StringConverter''' tests are '''StringConverterTest'''
+
* 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==
==Test method naming==
-
All testing methods must have '''clear and significant names'''. It is recommended, that each test method has name '''methodName__contitionsToTest''', 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()
-
If there are more than one method with the same name - add a suffix explaining method, starting with a dash (_), e.g.:
+
  formatString__onlyNumbers()
-
  testFormatString_2args()
+
  formatString__only_numbers()
-
  testFormatString_4args()
+
  formatString__tooManyPlaceholders()
-
If for some reason you want to have more than one test for one method add significant soffix explaining test purpouse:
+
  formatString__too_many_placeholders()
-
  testFormatString_Diacretics()
+
-
  testFormatString_HtmlEscapes()
+

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