Skip to content

Testing Standards

To ensure our Hexagonal Architecture remains pure, we enforce architectural rules via tests. Every new service must utilize ArchUnit to validate dependencies.

  1. Domain Isolation: The Domain layer must NOT depend on Application or Infrastructure.
    • Violation: Importing a Controller into an Entity.
  2. Infrastructure Isolation: The Infrastructure layer can depend on everything, but nothing should depend on Infrastructure (except main/bootstrapping).
  3. Naming Conventions: Classes must follow the naming standards defined in Hexagonal Architecture.
ArchitectureTest.java
package com.company.project;
import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import static com.tngtech.archunit.library.Architectures.onionArchitecture;
@AnalyzeClasses(packages = "com.company.project", importOptions = ImportOption.DoNotIncludeTests.class)
public class ArchitectureTest {
@ArchTest
static final ArchRule hexagonal_architecture_is_respected = onionArchitecture()
.domainModels("..domain.model..")
.domainServices("..domain.service..")
.applicationServices("..application..")
.adapter("persistence", "..infrastructure.persistence..")
.adapter("web", "..infrastructure.web..");
}
  • Unit Tests: Cover 100% of Domain Logic. Fast, no Spring Context (@SpringBootTest). Use JUnit 5 + Mockito.
  • Integration Tests: Verify Adapters (@DataJpaTest, @WebMvcTest).
  • E2E Tests: Verify critical flows with full context (@SpringBootTest).