### Konsist Test Flowchart Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/getting-started/README.md Visual representation of the steps involved in performing Konsist checks, distinguishing between declaration and architecture checks. ```mermaid %%{init: {'theme':'forest'}}%% flowchart TB Step1["1\. Create The Scope"]-->StepD2 Step1["1\. Create The Scope"]-->StepA2 StepD2["2\. Query and Filter The Declarations"]-->StepD3 StepD3["3\. Assert"] StepA2["2\. Assert Architecture"]-->StepA3 StepA3["2a. Define Layers"]-->StepA4 StepA4["2b. Define Architecture Assertions"] style Step1 fill:#52B523,stroke:#666,stroke-width:2px,color:#fff ``` -------------------------------- ### Konsist Workflow Example Source: https://github.com/lemonappdev/konsist-documentation/blob/main/writing-tests/koscope.md A flowchart illustrating the typical workflow in Konsist, starting from creating a scope, filtering declarations, and defining assertions. ```mermaid %%{init: {'theme':'forest'}}%% flowchart TB Step1["1\. Create The Scope"] --> StepD2 Step1["1\. Create The Scope"]-->StepA2 StepD2["2\. Filter Declarations"] --> StepD3 StepD3["3\. Define Assertion"] StepA2["2\. Assert Architecture"] --> StepA3 StepA3["2a. Define Layers"] --> StepA4 StepA4["2b. Define Assertion"] style Step1 fill:#52B523,stroke:#666,stroke-width:2px,color:#fff ``` -------------------------------- ### Konsist Overview and Capabilities Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/articles.md Get a comprehensive overview of Konsist's capabilities, including its role in dynamic testing and its broader implications for Kotlin development. ```en A Tour Through Konsist https://youtu.be/AlYTvzwZOc4 ``` ```en Konsist: First experience with the new linter for Kotlin https://www.droidcon.com/2023/10/17/konsist-first-experience-with-the-new-linter-for-kotlin/ ``` ```en Konsist: More than you might think https://medium.com/@kacper.wojciechowski/konsist-is-more-than-you-might-think-3a2bdc498425 ``` ```en Kotlin β€œLint” Testing With Konsist https://blog.stackademic.com/kotlin-lint-testing-with-konsist-63756e80cf5a ``` -------------------------------- ### Query All Functions Source: https://github.com/lemonappdev/konsist-documentation/blob/main/veryfying-codebase/verify-functions.md Starts the process of verifying functions by querying all functions present in the project scope. ```kotlin Konsist .scopeFromProject() .functions() ... ``` -------------------------------- ### Query All Properties Source: https://github.com/lemonappdev/konsist-documentation/blob/main/veryfying-codebase/verify-properties.md This snippet demonstrates how to query all properties within a project using the Konsist library. It serves as a starting point for property verification. ```kotlin Konsist .scopeFromProject() .properties() ... ``` -------------------------------- ### Query All Classes Source: https://github.com/lemonappdev/konsist-documentation/blob/main/veryfying-codebase/verify-classes.md Starts the verification process by selecting all classes present in the project codebase. This is a foundational step for most class verification tasks. ```kotlin Konsist .scopeFromProject() .classes() ... ``` -------------------------------- ### Kotlin Type Declaration Example Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/declaration-references.md Demonstrates a Kotlin property declaration with a custom type 'Foo'. This serves as a basic example for understanding type representation in Konsist. ```kotlin val foo: Foo ``` -------------------------------- ### Verify Function Name Starts With 'get' Source: https://github.com/lemonappdev/konsist-documentation/blob/main/veryfying-codebase/verify-functions.md Checks if a function's name begins with the prefix 'get', ensuring adherence to naming conventions. ```kotlin ... .assertTrue { it.hasNameStartingWith("get") } ``` -------------------------------- ### Select Classes in Packages with Prefix Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/packageselector.md Demonstrates selecting classes that reside in packages starting with 'com.app..'. The `..` acts as a wildcard for zero or more packages. ```kotlin Konsist .scopeFromProject() .classes() .assertTrue { it.resideInPackages("com.app..") } // com.app.data - valid // com.app.data.repository - valid // com.data - invalid // com - invalid ``` -------------------------------- ### Verify Method Name Starting Source: https://github.com/lemonappdev/konsist-documentation/blob/main/veryfying-codebase/verify-interfaces.md Checks if methods (functions within an interface) have names that start with a specific prefix, like 'Local'. This is useful for enforcing method naming conventions. ```kotlin ... .functions() .assertTrue { it.hasNameStartingWith("Local") } ``` -------------------------------- ### Query All Interfaces Source: https://github.com/lemonappdev/konsist-documentation/blob/main/veryfying-codebase/verify-interfaces.md This snippet demonstrates how to query all interfaces present in a project using Konsist. It serves as a starting point for interface verification, though practical scenarios often involve filtering for specific subsets of interfaces. ```kotlin Konsist .scopeFromProject() .interfaces() ... ``` -------------------------------- ### Integrating Konsist with GitHub Actions Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/articles.md This guide explains how to integrate Konsist and Ktlint into a GitHub Actions Continuous Integration pipeline for automated code quality checks. ```en Adding Konsist and Ktlint to a GitHub Actions Continuous Integration https://akjaw.com/konsist-and-ktlint-in-github-actions-continous-integration/ ``` -------------------------------- ### Query and Filter Declarations Combined Source: https://github.com/lemonappdev/konsist-documentation/blob/main/writing-tests/query-and-filter-declarations.md An example combining querying and filtering steps: selecting classes in the 'controller' package, then querying their properties, and filtering those properties by the 'Inject' annotation. ```kotlin koScope .classes() // query all classes .resideInPackage("..controller") // filter classes in 'controller' package .properties() // query all properties .withAnnotationOf() // filter classes in 'controller' package .assertTrue { // .. } ``` -------------------------------- ### Konsist Declaration Check Example Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/getting-started/create-first-konsist-test-declaration-check.md Demonstrates a complete Konsist declaration check to verify that all classes annotated with '@RestController' reside in the '..controller' package. This involves creating a scope, retrieving classes, filtering by annotation, and asserting the package location. ```kotlin Konsist.scopeFromProject() .classes() .withAllAnnotationsOf(RestController::class) .assertTrue { it.resideInPackage("..controller") } ``` -------------------------------- ### Example of External Type Usage Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/declaration-references.md Demonstrates how an external type, like Android's ViewModel, is represented and handled by Konsist. Konsist has limited information about such types because they originate from external libraries and are not directly parsed from the project's source code. ```kotlin class MyViewModel: ViewModel ``` -------------------------------- ### Kotlin Multiplatform (KMP) Starter Projects Source: https://github.com/lemonappdev/konsist-documentation/blob/main/inspiration/starter-projects.md Provides links to starter projects for Kotlin Multiplatform development using different build tools and testing frameworks (JUnit 5, Kotest). ```text KMP - JUnit 5: - konsist-starter-kmp-gradle-kotlin-junit5 KMP - Kotest: - konsist-starter-kmp-gradle-kotlin-kotest ``` -------------------------------- ### Spring Starter Projects Source: https://github.com/lemonappdev/konsist-documentation/blob/main/inspiration/starter-projects.md Provides links to starter projects for Spring development using different build tools and testing frameworks (JUnit 5, Kotest). ```text Spring - JUnit 5: - spring-gradle-groovy-junit-5 - spring-gradle-kotlin-junit-5 - spring-maven-junit5 Spring - Kotest: - spring-gradle-kotlin-kotest - spring-gradle-groovy-kotest - spring-maven-kotest ``` -------------------------------- ### Verify Function Name Prefix with Annotation Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/declaration-vs-property.md An example of verifying that functions annotated with 'CustomLogger' have a name starting with 'log', using Konsist's filtering capabilities. ```kotlin // Every function with a name starting with "log" is annotated with CustomLogger koScope .functions() .withAllAnnotations("CustomLogger") .assertTrue { it.hasNameStartingWith("log") } ``` -------------------------------- ### Android Starter Projects Source: https://github.com/lemonappdev/konsist-documentation/blob/main/inspiration/starter-projects.md Provides links to starter projects for Android development using different build tools and testing frameworks (JUnit 4, JUnit 5, Kotest). ```text Android - JUnit 4: - android-gradle-groovy-junit-4 - android-gradle-kotlin-junit-4 Android - JUnit 5: - android-gradle-groovy-junit-5 - android-gradle-kotlin-junit-5 Android - Kotest: - android-gradle-groovy-kotest - android-gradle-kotlin-kotest ``` -------------------------------- ### JUnit 4 Static Test Example Source: https://github.com/lemonappdev/konsist-documentation/blob/main/advanced/dynamic-konsist-tests/explicit-test-names.md Example of a static test in JUnit 4, where passing `testName` to Konsist assertion methods is not required. ```kotlin @Test fun myTest() { Konsist.scopeFromProject() .classes() .assertTrue { ... } } ``` -------------------------------- ### JUnit 5 Static Test Example Source: https://github.com/lemonappdev/konsist-documentation/blob/main/advanced/dynamic-konsist-tests/explicit-test-names.md Example of a static test in JUnit 5 where `testName` does not need to be passed to Konsist assertion methods. ```kotlin @Test fun myTest() { Konsist.scopeFromProject() .classes() .assertTrue { ... } } ``` -------------------------------- ### Konsist vs. Other Linters and Dynamic Testing Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/articles.md Understand the differences between Konsist and other Kotlin linters like ArchUnit. Also, learn about embracing dynamic testing with Konsist. ```en ArchUnit vs. Konsist. Why Did We Need Another Kotlin Linter? https://proandroiddev.com/archunit-vs-konsist-why-did-we-need-another-linter-972c4ff2622d ``` ```en Konsist and Conquer: Embracing the World of Kotlin Dynamic Testing https://proandroiddev.com/konsist-and-conquer-embracing-the-world-of-dynamic-testing-07bf2fefcee1 ``` -------------------------------- ### Konsist Architecture Overview Source: https://github.com/lemonappdev/konsist-documentation/blob/main/help/contributing.md A high-level diagram illustrating the interaction between the Client, Konsist, and its Core components. ```mermaid %%{init: {'theme':'forest'}}%% flowchart LR subgraph Konsist direction TB direction LR Api --> Core end Client --> Konsist ``` -------------------------------- ### Add Konsist Snapshot Repository Source: https://github.com/lemonappdev/konsist-documentation/blob/main/advanced/konsist-snapshots.md Configures your build system to include the Konsist snapshot repository, allowing access to development builds. ```xml konsist-snapshots https://s01.oss.sonatype.org/content/repositories/snapshots/ true ``` -------------------------------- ### Verify Property Annotation Source: https://github.com/lemonappdev/konsist-documentation/blob/main/veryfying-codebase/verify-properties.md Verifies the presence of a specific annotation on a property. This example checks for the 'JsonProperty' annotation. ```kotlin ... .assertTrue { it.hasAnnotationOf(JsonProperty::class) } ``` -------------------------------- ### Creating a Scope from Project Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/getting-started/create-first-konsist-test-declaration-check.md Shows how to initialize a Konsist scope that includes all Kotlin files within the current project using `scopeFromProject()`. ```kotlin // Define the scope containing all Kotlin files present in the project Konsist.scopeFromProject() //Returns KoScope ``` -------------------------------- ### Declare CustomLogger Annotation Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/declaration-vs-property.md Demonstrates the declaration of a custom annotation class named 'CustomLogger' in Kotlin. This is an example of a declaration-site construct. ```kotlin annotation class CustomLogger ``` -------------------------------- ### Forking Konsist Documentation Repository Source: https://github.com/lemonappdev/konsist-documentation/blob/main/help/contributing.md Instructions for forking the Konsist documentation repository. This is where changes to the project's documentation website are made. ```git git clone --recursive https://github.com/LemonAppDev/konsist-documentation.git ``` -------------------------------- ### Query All Properties Inside Classes Source: https://github.com/lemonappdev/konsist-documentation/blob/main/writing-tests/declaration-query-and-filter.md Shows how to first get all classes from a scope and then retrieve all properties defined within those classes. ```kotlin koScope .classes() .properties() .assertTrue { //... } ``` -------------------------------- ### Get All Classes from Scope Source: https://github.com/lemonappdev/konsist-documentation/blob/main/writing-tests/declaration-query-and-filter.md Demonstrates how to retrieve all classes present within a given Konsist scope using the `classes()` method. ```kotlin koScope .classes() ``` -------------------------------- ### Filter Classes by Annotation and Package Source: https://github.com/lemonappdev/konsist-documentation/blob/main/writing-tests/declaration-query-and-filter.md Example of chaining filters to select classes that have a specific annotation and belong to a particular package pattern. ```kotlin koScope .classes() .withAllAnnotationsOf(UseCase::class) .withPackage("..usecase") .assertTrue { //... } ``` -------------------------------- ### Konsist Kotlin Linter Introduction Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/articles.md Learn about Konsist, a cutting-edge linter designed to enforce consistency and architectural guidelines in Kotlin codebases. This article introduces the core concepts and benefits of using Konsist. ```en Introducing Konsist: A Cutting-Edge Kotlin Linter https://blog.kotlin-academy.com/introducing-konsist-a-cutting-edge-kotlin-linter-d3ab916a5461 ``` ```en Konsist: First experience with the new linter for Kotlin https://proandroiddev.com/konsist-first-experience-with-the-new-linter-for-kotlin-9153b0e7e2c3 https://www.droidcon.com/2023/10/17/konsist-first-experience-with-the-new-linter-for-kotlin/ ``` ```fr Standardisez votre codebase avec Konsist https://www.youtube.com/watch?v=_bn77FkZkUM ``` -------------------------------- ### Advanced Konsist Usage and Architecture Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/articles.md Explore advanced topics related to Konsist, including custom baseline definitions, refactoring multi-module projects, and protecting project architecture. ```en Konsist adoption with a custom Baseline definition https://medium.com/@chethan.n/we-randomly-stumbled-upon-konsist-and-were-excited-about-the-possibilities-it-offered-bd4e0db51090 ``` ```en Refactoring Multi-Module Kotlin Project With Konsist https://medium.com/p/f0de0de59a3d ``` ```en Protect Kotlin Project Architecture Using Konsist https://proandroiddev.com/protect-kotlin-project-architecture-using-konsist-3bfbe1ad0eea ``` ```en Konsist: Protect Kotlin Multiplatform projects from architecture guidelines violations https://medium.com/@lahirujay/konsist-protect-kotlin-multiplatform-projects-from-architecture-guidelines-violations-d88db0614cbd https://medium.com/@lahirujay/konsist-protect-kotlin-multiplatform-projects-from-architecture-guidelines-violations-d88db0614cbd ``` -------------------------------- ### Konsist Architectural Check Steps Diagram Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/getting-started/create-secound-konsist-test-architectural-check.md A Mermaid diagram outlining the three high-level steps required to write a Konsist architectural check: Define Layers, Create The Scope, and Assert Architecture. ```mermaid %%{init: {'theme':'forest'}}%% flowchart TB Step1["1. Define Layers"]-->Step2 Step2["2. Create The Scope"]-->Step3 Step3["3. Assert Architecture"] ``` -------------------------------- ### Verify Property Type Source: https://github.com/lemonappdev/konsist-documentation/blob/main/veryfying-codebase/verify-properties.md Ensures that a property has a specific type, promoting type safety and adherence to project standards. This example checks for 'LocalDateTime'. ```kotlin ... .assertTrue { it.type?.name == "LocalDateTime" } ``` -------------------------------- ### Type Represented by Import Alias Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/declaration-references.md Shows how Konsist handles import aliases, with an example test to verify the 'internal' modifier of the imported declaration. ```kotlin import com.app.Foo as MyFoo val foo: MyFoo? = null ``` ```kotlin scope .properties() .types .assertTrue { it .asTypeAliasDeclaration .type .asInterfaceDeclaration .hasInternalModifier } ``` -------------------------------- ### Type Represented by Interface Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/declaration-references.md Illustrates how Konsist handles declarations representing Kotlin interfaces. The example verifies the 'internal' modifier on an interface declaration. ```kotlin internal interface Foo ``` ```kotlin val foo: Foo? = null ``` ```kotlin scope .properties() .types .assertTrue { it.asInterfaceDeclaration?.hasInternalModifier } ``` -------------------------------- ### Add Konsist Snapshot Repository Source: https://github.com/lemonappdev/konsist-documentation/blob/main/advanced/konsist-snapshots.md Configures your build system to include the Konsist snapshot repository, allowing access to development builds. ```groovy repositories { // Konsist snapshot repository maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' } // More repositories } ``` -------------------------------- ### Running Konsist Tests Source: https://github.com/lemonappdev/konsist-documentation/blob/main/advanced/isolate-konsist-tests.md Commands to execute Konsist tests using Gradle and Maven. ```shell ./gradlew app:konsistTest ``` ```yaml mvn test ``` -------------------------------- ### Strict Dependency Example Source: https://github.com/lemonappdev/konsist-documentation/blob/main/writing-tests/architecture-assert.md Explains and demonstrates the `strict` parameter in `dependsOn`. When `strict` is true, it enforces a mandatory dependency; when false (default), it allows optional dependency. ```kotlin // Optional dependency - Feature layer may depend on Domain layer featureLayer.dependsOn(domainLayer) // strict = false by default // Required dependency - Feature layer must depend on Domain layer featureLayer.dependsOn(domainLayer, strict = true) ``` -------------------------------- ### Add Konsist Snapshot Repository Source: https://github.com/lemonappdev/konsist-documentation/blob/main/advanced/konsist-snapshots.md Configures your build system to include the Konsist snapshot repository, allowing access to development builds. ```kotlin repositories { // Konsist snapshot repository maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") // More repositorues } ``` -------------------------------- ### Filter Classes by Annotation (filter) Source: https://github.com/lemonappdev/konsist-documentation/blob/main/writing-tests/declaration-query-and-filter.md Example of filtering classes that are annotated with a specific annotation (e.g., `UseCase`) using the standard Kotlin `filter` method. ```kotlin koScope .classes() .filter { it.hasAnnotationOf() } .assertTrue { //... } ``` -------------------------------- ### Konsist Flowchart Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/getting-started/create-first-konsist-test-declaration-check.md Visual representation of the four high-level steps involved in writing a Konsist declaration check: Create The Scope, Retrieve Declarations, Filter Declarations, and Define Assertion. ```mermaid %%{init: {'theme':'forest'}}%% flowchart TB Step1["1. Create The Scope"]-->Step2 Step2["2. Retrieve Declarations"]-->Step3 Step3["3. Filter Declarations"]-->Step4 Step4["4. Define Assertion"] ``` -------------------------------- ### Kotest Dynamic Test with Konsist Source: https://github.com/lemonappdev/konsist-documentation/blob/main/advanced/dynamic-konsist-tests/explicit-test-names.md Example of using Kotest for dynamic tests with Konsist, demonstrating how to retrieve and pass the test name using `this.testCase.name.testName`. ```kotlin class SampleDynamicKonsistTest : FreeSpec({ Konsist .scopeFromProject() .classes() .withNameEndingWith("UseCase") .forEach { useCase -> "${useCase.name} should have test" { useCase.assertTrue(testName = this.testCase.name.testName) { it.hasTestClass() } } "${useCase.name} should reside in ..domain.usecase.. package" { useCase.assertTrue(testName = this.testCase.name.testName) { it.resideInPackage("..domain.usecase..") } } } }) ``` -------------------------------- ### Publishing Konsist Artifact to Local Maven Repository Source: https://github.com/lemonappdev/konsist-documentation/blob/main/help/contributing.md Publish a SNAPSHOT artifact of Konsist to your local Maven repository to test local changes. This command uses a Gradle property to specify the release target. ```bash ./gradlew publishToMavenLocal -Pkonsist.releaseTarget=local ``` -------------------------------- ### Enable Full Exception Logging in Gradle Source: https://github.com/lemonappdev/konsist-documentation/blob/main/advanced/enable-full-command-line-logging.md Configure Gradle's test logging to display the full exception format, including stack traces and declaration details. This is essential for pinpointing assertion failures in Konsist tests. ```kotlin tasks.withType { testLogging { events(TestLogEvent.FAILED) exceptionFormat = TestExceptionFormat.FULL } } ``` ```groovy tasks.test { testLogging { events(TestLogEvent.FAILED) exceptionFormat = TestExceptionFormat.FULL } } ``` -------------------------------- ### Type Represented by Kotlin Type Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/declaration-references.md Explains Konsist's handling of built-in Kotlin types, using 'String' as an example and demonstrating a test to check its name. ```kotlin // Kotlin internal source code for String val foo: String? = null ``` ```kotlin scope .properties() .types .assertTrue { it.asKotlinTypeDeclaration.name == "String" } ``` -------------------------------- ### Print All Declarations Source: https://github.com/lemonappdev/konsist-documentation/blob/main/writing-tests/query-and-filter-declarations.md Demonstrates how to print all retrieved declarations to the console using the `print()` method. ```kotlin koScope .classes() .properties() .print() ``` -------------------------------- ### Verify Boolean Property Name Source: https://github.com/lemonappdev/konsist-documentation/blob/main/veryfying-codebase/verify-properties.md Validates if a Boolean property's name starts with 'is', ensuring adherence to common naming conventions for boolean flags. ```kotlin ... .assertTrue { it.type?.name == "Boolean" && it.hasNameStartingWith("is") } ``` -------------------------------- ### Creating a Pull Request for Konsist Source: https://github.com/lemonappdev/konsist-documentation/blob/main/help/contributing.md After implementing changes and adding tests, create a draft Pull Request targeting the 'develop' branch. Ensure all automated checks pass before marking the PR as 'Ready for review'. ```git # After implementing changes and adding tests git add . git commit -m "Your commit message" git push origin your-feature-branch # Create Pull Request targeting 'develop' branch ``` -------------------------------- ### Verify Annotation Package Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/declaration-vs-property.md An example of verifying that annotation classes reside in a specific package ('..annotation..') using Konsist. It filters declarations with annotation modifiers. ```kotlin // Every annotation class must reside in the "annotation" package koScope .classes() .withAnnotationModifier() .assertTrue { it.resideInPackage("..annotation..") } ``` -------------------------------- ### Running Konsist Checks Locally Source: https://github.com/lemonappdev/konsist-documentation/blob/main/help/contributing.md Execute various checks for the Konsist codebase locally using Gradle tasks. These include code formatting with Spotless and ktlint, static analysis with Detekt, and different types of tests (unit, API, integration, and Konsist tests). ```bash ./gradlew spotlessCheck ./gradlew spotlessApply ./gradlew detektCheck ./gradlew detektApply ./gradlew lib:test ./gradlew lib:apiTest ./gradlew lib:integrationTest ./gradlew lib:konsistTest ``` -------------------------------- ### Konsist Dependencies Licenses Source: https://github.com/lemonappdev/konsist-documentation/blob/main/help/open-source-licenses.md A list of third-party libraries, plugins, and tools used by the Konsist project, along with their respective licenses and pages. ```APIDOC Dependencies: - Kotlin: License: Apache-2.0 License Page: https://github.com/JetBrains/kotlin - Kotlin-compiler: License: Apache-2.0 License Page: https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-compiler - Mockk: License: Apache-2.0 License Page: https://mockk.io/ - Spotless: License: Apache-2.0 License Page: https://github.com/diffplug/spotless - Gradle Test Logger Plugin: License: Apache-2.0 License Page: https://github.com/radarsh/gradle-test-logger-plugin - JUnit: License: Eclipse Public License - v 2.0 Page: https://junit.org/junit5/ - Kotest: License: Apache-2.0 License Page: https://kotest.io/ - Gradle: License: Apache-2.0 License Page: https://gradle.org/ - Ktlint: License: MIT License Page: https://pinterest.github.io/ktlint/latest/ - Detekt: License: Apache-2.0 License Page: https://github.com/detekt/detekt - Dokka: License: Apache-2.0 License Page: https://github.com/Kotlin/dokka ``` -------------------------------- ### Branching Strategy for Konsist Docs Source: https://github.com/lemonappdev/konsist-documentation/blob/main/help/contributing.md When contributing to Konsist documentation, branch off the 'main' branch of the konsist-documentation repository. ```git git checkout main # Make changes to documentation git checkout -b docs-feature-branch ``` -------------------------------- ### Accessing Type Properties with Casting Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/declaration-references.md Illustrates how to access specific properties of a type declaration using explicit casting in Konsist. This example checks if a class declaration has all specified annotations. ```kotlin Konsist .scopeFromProject() .properties() .types .assertTrue { koTypeDeclaration -> val koClass = koTypeDeclaration as KoClassDeclaration koClass.hasAllAnnotations { it.representsTypeOf() } } ``` -------------------------------- ### Konsist Declaration Querying Flow Source: https://github.com/lemonappdev/konsist-documentation/blob/main/writing-tests/query-and-filter-declarations.md Visual representation of the Konsist declaration querying process, showing the steps from creating a scope to asserting declarations. ```mermaid %%{init: {'theme':'forest'}}%% flowchart TB Step1["1\. Create The Scope"]-->Step2 Step2["2\. Query and Filter The Declarations"]-->Step3 Step3["3\. Assert"] style Step2 fill:#52B523,stroke:#666,stroke-width:2px,color:#fff ``` -------------------------------- ### Mermaid Diagram: Architecture Assertion Flow Source: https://github.com/lemonappdev/konsist-documentation/blob/main/writing-tests/architecture-assert.md A Mermaid flowchart depicting the steps involved in architecture assertion within Konsist, starting from scope creation and progressing through layer definition and assertion. ```mermaid %%{init: {'theme':'forest'}}%% flowchart TB StepA2["2. Assert Architecture"]-->StepA3 StepA3["2a. Define Layers"]-->StepA4 StepA4["2b. Define Assertion"] style StepA2 fill:#52B523,stroke:#666,stroke-width:2px,color:#fff style StepA3 fill:#52B523,stroke:#666,stroke-width:2px,color:#fff style StepA4 fill:#52B523,stroke:#666,stroke-width:2px,color:#fff ``` -------------------------------- ### Classes with RestController Annotation Should Never Return Collection Source: https://github.com/lemonappdev/konsist-documentation/blob/main/inspiration/snippets/spring-snippets.md Validates that classes annotated with `@RestController` do not have functions returning types starting with 'List'. This aims to prevent direct return of collection types. ```kotlin import org.springframework.web.bind.annotation.RestController @Test fun `classes with 'RestController' annotation should never return collection`() { Konsist .scopeFromPackage("story.controller..") .classes() .withAnnotationOf(RestController::class) .functions() .assertFalse { function -> function.hasReturnType { it.hasNameStartingWith("List") } } } ``` -------------------------------- ### Create Project Scope for Konsist Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/getting-started/create-secound-konsist-test-architectural-check.md Obtains a `KoScope` instance representing all Kotlin files within the project. This scope is used as the entry point for performing architectural checks and assertions. ```kotlin Konsist // Define layers private val presentationLayer = Layer("Presentation", "com.myapp.presentation..") private val domainLayer = Layer("Domain", "com.myapp.domain..") private val dataLayer = Layer("Data", "com.myapp.data..") // Define the scope containing all Kotlin files present in the project Konsist.scopeFromProject() //Returns KoScope ``` -------------------------------- ### KoTest Test for Architecture Dependencies Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/getting-started/create-secound-konsist-test-architectural-check.md A KoTest test class that integrates Konsist architecture assertions. This example demonstrates how to test layer dependencies within a KoTest FreeSpec, ensuring architectural rules are met. ```kotlin class ArchitectureKonsistTest { class UseCaseTest : FreeSpec({ "architecture layers have dependencies correct" { Konsist .scopeFromProject() .assertArchitecture { private val presentationLayer = Layer("Presentation", "com.myapp.presentation..") private val domainLayer = Layer("Domain", "com.myapp.business..") private val dataLayer = Layer("Data", "com.myapp.data..") // Define layer dependnecies presentationLayer.dependsOn(domainLayer) dataLayer.dependsOn(domainLayer) domainLayer.dependsOnNothing() } } }) } ``` -------------------------------- ### Create Project Scope Source: https://github.com/lemonappdev/konsist-documentation/blob/main/writing-tests/koscope.md Creates a scope containing all Kotlin files present in the project. This is the widest scope available and includes all production and test code. ```kotlin Konsist.scopeFromProject() // All Kotlin files present in the project ``` -------------------------------- ### Test Classes Should Have Test Subject Named Sut Source: https://github.com/lemonappdev/konsist-documentation/blob/main/inspiration/snippets/junit-snippets.md Validates that test classes have a property named 'sut' (System Under Test) which correctly reflects the type of the class being tested. This improves clarity and maintainability of test setups. ```kotlin import org.junit.jupiter.api.Test import com.lemonappdev.konsist.api.Konsist @Test fun `test classes should have test subject named sut`() { Konsist .scopeFromTest() .classes() .assertTrue { // Get type name from test class e.g. FooTest -> Foo val type = it.name.removeSuffix("Test") val sut = it .properties() .firstOrNull { property -> property.name == "sut" } sut != null && sut.hasTacitType(type) } } ``` -------------------------------- ### No empty files allowed Source: https://github.com/lemonappdev/konsist-documentation/blob/main/inspiration/snippets/general-snippets.md Ensures that no files in the project are empty. This rule helps prevent accidental creation of empty files and promotes complete code implementation. ```kotlin @Test fun `no empty files allowed`() { Konsist .scopeFromProject() .files .assertFalse { it.text.isEmpty() } } ``` -------------------------------- ### Flowchart of Dynamic Test Generation Source: https://github.com/lemonappdev/konsist-documentation/blob/main/advanced/dynamic-konsist-tests/README.md A Mermaid flowchart illustrating the relationship between rules and use cases in generating dynamic tests. It shows how each rule is applied to different use cases to produce specific test cases. ```Mermaid %%{init: {'theme':'forest'}}%% flowchart LR D1["πŸ› οΈ RULE Verify use case package"] D1 --> D1T1 D1 --> D2T1 D1 --> D3T1 D2["πŸ› οΈ RULE Verify use case has test"] D2 --> D1T2 D2 --> D2T2 D2 --> D3T2 D1T1["βœ… TEST Verify use case package (CategorizeGroceryItemsUseCase)"] D1T2["βœ… TEST Verify use case has test (CategorizeGroceryItemsUseCase)"] D2T1["βœ… TEST Verify use case package (AdjustCaloricGoalUseCase)"] D2T2["βœ… TEST Verify use case has test (AdjustCaloricGoalUseCase)"] D3T1["βœ… TEST Verify use case package (CalculateDailyIntakeUseCase)"] D3T2["βœ… TEST Verify use case has test (CalculateDailyIntakeUseCase)"] ``` -------------------------------- ### Check Parent Class Modifiers Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/declaration-references.md This example shows how to access parent classes of declarations and check for specific modifiers, such as the 'internal' modifier. It's helpful for ensuring that parent classes adhere to specific visibility or structural rules. ```kotlin fun `all parrent interfaces are internal`() { Konsist .scopeFromProject() .classes() .parentInterfaces() .assertTrue { it.hasInternalModifier() } } ``` -------------------------------- ### Enable Parallel Execution in JUnit5 Source: https://github.com/lemonappdev/konsist-documentation/blob/main/advanced/additional-junit5-setup.md Configure JUnit5 to run tests in parallel by setting properties in `junit-platform.properties`. This file should be placed in the `resources` directory of your test source set. The properties enable parallel execution, set the default mode to concurrent, and configure a dynamic thread pool. ```properties junit.jupiter.execution.parallel.enabled=true junit.jupiter.execution.parallel.mode.default=concurrent junit.jupiter.execution.parallel.config.strategy=dynamic junit.jupiter.execution.parallel.config.dynamic.factor=0.95 ``` -------------------------------- ### Adding Local Maven Repository to Maven Projects Source: https://github.com/lemonappdev/konsist-documentation/blob/main/help/contributing.md Configure Maven projects to use the local Maven repository. This involves adding a repository block with the local repository URL to the pom.xml file. ```xml local file://${user.home}/.m2/repository ``` -------------------------------- ### Creating a Pull Request for Konsist Docs Source: https://github.com/lemonappdev/konsist-documentation/blob/main/help/contributing.md After making changes to the documentation, create a new Pull Request targeting the 'main' branch of the konsist-documentation repository. ```git # After making documentation changes git add . git commit -m "Update documentation" git push origin docs-feature-branch # Create Pull Request targeting 'main' branch ``` -------------------------------- ### Kotlin Code Snippet Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/declaration.md A sample Kotlin file containing a property declaration and a class declaration with a function. ```kotlin private const val logLevel = "debug" @Entity open class Logger(val level: String) { fun log(message: String) { } } ``` -------------------------------- ### Print Konsist Declarations Before and After Query Source: https://github.com/lemonappdev/konsist-documentation/blob/main/features/debug-konsist-test.md Demonstrates printing lists of declarations before and after applying a query (e.g., withSomeAnnotations) using Konsist's print API with prefixes. ```kotlin koScope .classes() // List .print(prefix = "Before") // or .print(prefix = "Before") { it.name } .withSomeAnnotations("Logger") .print(prefix = "After") // or .print(prefix = "After") { it.name } ``` -------------------------------- ### Dependency Versions Configuration Source: https://github.com/lemonappdev/konsist-documentation/blob/main/help/open-source-licenses.md Details on the dependency versions used in the Konsist project, typically managed in a libs.versions.toml file. ```Gradle [versions] kotlin = "1.9.0" kotest = "5.5.5" junit = "5.10.0" mockk = "1.13.7" spotless = "6.23.1" detekt = "1.22.0" dokka = "1.7.20" ktlint = "0.49.0" [libraries] kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" } kotest-runner-junit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" } junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" } mockk = { module = "io.mockk:mockk", version.ref = "mockk" } spotless-plugin = { module = "com.diffplug.spotless:spotless-plugin", version.ref = "spotless" } detekt-gradle-plugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" } dokka-gradle-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" } ktlint-gradle-plugin = { module = "org.jlleitschuh.gradle:ktlint-gradle-plugin", version.ref = "ktlint" } [plugins] kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } spotless = { id = "com.diffplug.spotless", version.ref = "spotless" } detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" } ``` -------------------------------- ### Add Maven Central Repository Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/getting-started/add-konsist-dependency.md This snippet shows how to add the Maven Central repository to your build configuration, which is required to download the Konsist library. ```gradle repositories { mavenCentral() } ``` -------------------------------- ### Add Konsist Dependency for Gradle (Groovy) Source: https://github.com/lemonappdev/konsist-documentation/blob/main/getting-started/getting-started/add-konsist-dependency.md Adds the Konsist testing dependency to your `build.gradle` file for Groovy projects. ```groovy dependencies { testImplementation "com.lemonappdev:konsist:0.17.3" } ```