Create Secound Konsist Test - Architectural Check
Last updated
Last updated
Konsist's Architectural Checks
serve as a robust tool for maintaining layer isolation, enabling development teams to enforce strict boundaries between different architectural layers. Here few things that can be verified with Konsist:
domain
layer is independant
data
layer depends on domain layer
...
Let's write a simple test to verify that application architecture rules are preserved. In this scenario, the application follows a simple 3-layer architecture, where Presentation
and Data
layers depend on Domain
layer and Domain
layer is independant (from these layers):
On a high level writing Konsist architectural check
requires 3 steps:
Let's take a closer look at each of these steps.
Create layers instances to represent project layers. Each Layer
instance accepts the name
(used for presenting architecture violation errors) and package
used to define layers.
The Konsist
object is an entry point to the Konsist
library.
The scopeFromX
methods obtains the instance of the scope containing Kotlin project files. To get all Kotlin project files present in the project use the scopeFromProject
method:
To performa assertion use the assertArchiteture
method:
Utilize dependsX
methods to validate that your project's layers adhere to the defined architectural dependencies:
Wrap Konsist Code In Test
Note that test class has a KonsistTest
suffix. This is the recommended approach to name classes containing Konsist tests.
This section described the basic way of writing Konsist architectural test. To get a better understanding of how Konsist API works see Debug Konsist Test.
The declaration validation logic should be protected through automated testing. By wrapping Konsist checks within standard testing frameworks such as or , you can verify these rules with each :
The testing framework project dependency should be added to the project. See to get a complete sample project.
The testing framework project dependency should be added to the project. See to get a complete sample project.