Testing
Unit tests
JUnit tests are the simple and fast tests that use mocks to check simple, single functionality. You should write JUnit to check every function that you use in your code. JUnit must be fast, it should be matters of seconds to run that test.
Naming param is <className>Test.java
Integration tests
Integration tests are here to check whenever the functions that you use in code work well together. Those tests may take longer to run. In maven they are run in integration-test phase.
Naming param is <className>IT.java, or <className>IntegrationTest.java.
Acceptance tests
Acceptance testing is a testing technique performed to determine whether or not the software system has met the requirement specifications. The main purpose of this test is to evaluate the system's compliance with the business requirements and verify if it is has met the required criteria for delivery to end users.
There are various forms of acceptance testing: User Acceptance Testing, Business Acceptance Testing, Alpha Testing, Beta Testing.
Naming param is AcceptanceTest<className>.java.
Cucumber
Cucumber is a software tool used by computer programmers for testing other software. It runs automated acceptance tests written in a behavior-driven development (BDD) style. Central to the Cucumber BDD approach is its plain language parser called Gherkin. It allows expected software behaviors to be specified in a logical language that customers can understand. As such, Cucumber allows the execution of feature documentation written in business-facing text.
Testing with Cucumber
To start working with Cucumber we have to add following dependencies to project:
<dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-java</artifactId> <version>1.2.5</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-junit</artifactId> <version>1.2.5</version> <scope>test</scope> </dependency>
To make a executable test you have to prepare 3 files: Feature description, Steps definition and Runner file.
FeatureĀ file should be located in resources directory, i.e. (...)/<moduleName>/src/test/resources/cucumber/<FeatureFileName>.feature
It is preferred that Steps definitions file is located in following directory (...)/<moduleName>/src/test/java/steps/<StepsFileName>.java
Runner file like all tests should be located in (...)/<moduleName>/src/test/java/AcceptanceTest<TestedClassName>.java