Skip to content

Commit 149cbd0

Browse files
test(architecture): add clean architecture test
1 parent c412650 commit 149cbd0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.library.Architectures.layeredArchitecture
13+
import io.kotest.core.spec.style.StringSpec
14+
15+
class CleanArchitectureTest : StringSpec({
16+
"Test that the layers of Clean Architecture are respected" {
17+
layeredArchitecture()
18+
.consideringAllDependencies()
19+
.layer("entity").definedBy("..entity..")
20+
.layer("usecase").definedBy("..usecase..")
21+
.layer("application").definedBy("..application..")
22+
.layer("infrastructure").definedBy("..infrastructure..")
23+
.whereLayer("entity").mayOnlyBeAccessedByLayers("usecase", "application", "infrastructure")
24+
.whereLayer("usecase").mayOnlyBeAccessedByLayers("application", "infrastructure")
25+
.whereLayer("application").mayOnlyBeAccessedByLayers("infrastructure")
26+
.whereLayer("infrastructure").mayNotBeAccessedByAnyLayer()
27+
.check(
28+
ClassFileImporter()
29+
.withImportOption { !it.contains("/test/") } // ignore tests classes
30+
.importPackages("entity", "usecase", "application", "infrastructure")
31+
)
32+
}
33+
})

0 commit comments

Comments
 (0)