Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Folder structure in Test module

I am new in Spring and Testing as well. I have question about folder structure in Spring Boot project for Test module.

Is following project structure ok for Integration and unit tests in Test module? Or what is the best practice for that? Thanks.

project/
├── main
└── test
    ├── integration
    │   └── SomeTestIT.java
    └── unit
        └── SomeTestU.java
like image 327
Denis Stephanov Avatar asked Apr 21 '26 16:04

Denis Stephanov


1 Answers

Spring and Spring Boot don't have specific recommendations about the test classes layout.

So instead, you should follow the conventions of your build tool, probably Gradle or Maven.
For them, src/test/java is designed to contain test classes to execute. Just keep it.

You could have both unit and integration tests inside this directory and make the difference between them with a suffix : Test for unit tests and IT for integration tests.
These are the Maven conventions for unit tests and integration tests.
By sticking to them, you would have much less effort to setup the tests facilities.

Surefire (unit test) :

Inclusions

By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:

"**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".

"**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".

"**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".

"**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".

Failsafe Plugin (integration test) :

Inclusions

By default, the Failsafe Plugin will automatically include all test classes with the following wildcard patterns:

"**/IT*.java" - includes all of its subdirectories and all Java filenames that start with "IT".

"**/*IT.java" - includes all of its subdirectories and all Java filenames that end with "IT".

"**/*ITCase.java" - includes all of its subdirectories and all Java filenames that end with "ITCase".

like image 154
davidxxx Avatar answered Apr 23 '26 08:04

davidxxx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!