Skip to content

Commit e3f790a

Browse files
test(architecture): add archunit tests to enforce the following of clean architecture principles
1 parent 4af8f34 commit e3f790a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2023. Smart Operating Block
3+
*
4+
* Use of this source code is governed by an MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
package architecture
10+
11+
import com.tngtech.archunit.core.importer.ClassFileImporter
12+
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition
13+
import com.tngtech.archunit.library.Architectures.layeredArchitecture
14+
import io.kotest.core.spec.style.FunSpec
15+
16+
class CleanArchitectureTest : FunSpec({
17+
18+
test("Domain logic layer should not depend on any other layers") {
19+
ArchRuleDefinition
20+
.noClasses().that().resideInAPackage("..entities..")
21+
.should().dependOnClassesThat().resideInAPackage("..application..")
22+
.andShould().dependOnClassesThat().resideInAPackage("..infrastructure..")
23+
.check(ClassFileImporter().importPackages("..entities.."))
24+
}
25+
26+
test("Application layer should not depend on Infrastructure layer") {
27+
ArchRuleDefinition
28+
.noClasses().that().resideInAPackage("..application..")
29+
.should().dependOnClassesThat().resideInAPackage("..infrastructure..")
30+
.check(ClassFileImporter().importPackages("..application.."))
31+
}
32+
33+
test("The layer of architecture should respect clean architecture principles") {
34+
layeredArchitecture()
35+
.consideringAllDependencies()
36+
.layer("Entity").definedBy("..entities..")
37+
.layer("Application").definedBy("..application..")
38+
.layer("Infrastructure").definedBy("..infrastructure..")
39+
.whereLayer("Application").mayOnlyBeAccessedByLayers("Infrastructure")
40+
.whereLayer("Entity").mayNotAccessAnyLayer()
41+
}
42+
})

0 commit comments

Comments
 (0)