https://github.com/jabrena/pyramid-of-testing
A POC to increase the granularity of Test execution
https://github.com/jabrena/pyramid-of-testing
Last synced: 25 days ago
JSON representation
A POC to increase the granularity of Test execution
- Host: GitHub
- URL: https://github.com/jabrena/pyramid-of-testing
- Owner: jabrena
- Created: 2019-05-13T08:19:37.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-21T15:43:42.000Z (almost 6 years ago)
- Last Synced: 2025-02-13T10:48:18.786Z (3 months ago)
- Language: Java
- Homepage:
- Size: 60.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pyramid of testing
```
,/`.
,'/ __`.
,'_/_ _ _`.
,'__/_ ___ _ `.
,'_ /___ __ _ __ `.
'-.._/___...-"-.-..__`.```
# Context
When you are testing your API, you need to implement the Pyramid of testing.
In the development process, you will observe that some tests has a Slow performance like
the integration tests so, how to increase the granularity in the execution with Maven?## How to execute the tests with more granular control?
In JUnit 4, exist the Category concept and in JUnit 5, exist the concept about Tags.
Using this concept, it is possible to create some Interfaces, defining the type of tests:
``` java
public interface Unit { }
public interface Integration { }
```
and use it in your Tests:
``` java
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class TokenServiceTest {@Autowired
private TokenService tokenService;@Tag("unit")
@Test
public void demoTest(){assertThat(tokenService.getToken().length()).isEqualTo(TOKEN_LENGTH);
}}
```
The execution of the tests is managed by the Maven plugin Surefire.
Using the following combinations, you can satisfy your needs:
``` bash
mvn test
mvn test -Dgroups=unit
mvn test -Dgroups=integration
mvn test -Dgroups=unit,integration
mvn test -DexcludedGroups=unit
mvn test -DexcludedGroups=integration
mvn test -DexcludedGroups=unit,integration
mvn test -Dgroups=unit -DexcludedGroups=integration```
## References
- https://martinfowler.com/articles/practical-test-pyramid.html
- https://github.com/junit-team/junit4/wiki/categories
- https://junit.org/junit5/docs/current/user-guide/#writing-tests-tagging-and-filtering
- https://maven.apache.org/surefire/maven-surefire-plugin/