A well-organised test project is just as important as well-organised production code. Poor test structure leads to duplication, brittle tests, and test suites that are hard to navigate and maintain. This guide shows you exactly how to structure a JUnit 6 project — from package layout to naming conventions, test base classes, shared utilities, and the practices that keep test suites healthy at scale.
Whether you are starting fresh or cleaning up an existing project, the patterns here apply to any Java application — monolith, microservice, or library.
The Standard Maven/Gradle Directory Layout
JUnit 6 follows the standard Maven directory convention, which Gradle also adopts by default:
my-app/
├── src/
│ ├── main/
│ │ └── java/
│ │ └── com/example/
│ │ ├── service/
│ │ │ └── OrderService.java
│ │ ├── repository/
│ │ │ └── OrderRepository.java
│ │ └── model/
│ │ └── Order.java
│ └── test/
│ ├── java/
│ │ └── com/example/ <-- mirrors main package structure
│ │ ├── service/
│ │ │ └── OrderServiceTest.java
│ │ ├── repository/
│ │ │ └── OrderRepositoryIT.java <-- IT suffix = integration test
│ │ └── common/
│ │ └── BaseTest.java <-- shared test base class
│ └── resources/
│ └── junit-platform.properties <-- JUnit 6 config
├── pom.xml
└── README.md
Key principles of this layout:
- Test packages mirror production packages so you can immediately find the test for any class
- Unit tests end with
Test; integration tests end withIT - Shared test infrastructure lives in a
commonsub-package - JUnit 6 configuration goes in
src/test/resources/junit-platform.properties