Skip to content

Add Konsist as a arch unit test library#20

Open
alesrazym wants to merge 25 commits intodevelopfrom
feature/kmm_konsist
Open

Add Konsist as a arch unit test library#20
alesrazym wants to merge 25 commits intodevelopfrom
feature/kmm_konsist

Conversation

@alesrazym
Copy link
Collaborator

I have checked arch unit test libraries and implement sample with Konsist. If we go to use it, I can cover with more tests. If we have another library/solution, let's park now.

@alesrazym alesrazym requested a review from havlisimo January 15, 2024 21:11
@alesrazym alesrazym self-assigned this Jan 15, 2024
@havlisimo
Copy link
Owner

havlisimo commented Jan 16, 2024

zatim jsme vzdy pouzivali https://www.archunit.org/ je to sice pro Javu, ale tim, ze se Kotlin stejne prelozi do Javovskeho bytekodu, tak jsme s tim nemeli problem. Nicmene ten Konsist take nevypada spatne vzhledem k tomu ze je to primo psany pro Kotlin. U ArchUnit obcas narazime na nejaky problem ze necemu z Kotlinu nerozumi a pak se to ruzne hackuje

@alesrazym
Copy link
Collaborator Author

Prosvistel jsem clanky https://proandroiddev.com/archunit-vs-konsist-why-did-we-need-another-linter-972c4ff2622d a https://medium.com/the-house-of-code/archunit-vs-konsist-in-android-kotlin-oriented-codebase-b72c6c698b0b. Ja bych ten Konsist urcite zkusil :) Ale rozhodnuti tohoto typu maji delat nejzkusenejsi clenove tymu ;)

Pokud do toho pujdem, prozkoumal bych vzorovou integraci https://github.com/LemonAppDev/konsist/tree/develop/samples/starter-projects/konsist-starter-kmp-gradle-kotlin-junit5 a https://github.com/LemonAppDev/konsist/tree/develop/samples/starter-projects/konsist-starter-kmp-gradle-kotlin-kotest a jeste bych zvazil, zda neprejit na JUnit5 (to ted netusim, jestli to ma nejake potencialni problemy)

@alesrazym alesrazym force-pushed the feature/kmm_shared_modules branch 2 times, most recently from 1815086 to 165b503 Compare January 19, 2024 08:16
@alesrazym alesrazym force-pushed the feature/kmm_konsist branch from 8919ef5 to 608b229 Compare January 19, 2024 08:33
@alesrazym alesrazym changed the base branch from feature/kmm_shared_modules to feature/kmm_rebased January 22, 2024 07:22
@alesrazym alesrazym force-pushed the feature/kmm_rebased branch from 165b503 to 3f26286 Compare June 5, 2024 09:11
@alesrazym alesrazym deleted the branch develop June 5, 2024 09:14
@alesrazym alesrazym closed this Jun 5, 2024
@alesrazym alesrazym reopened this Jun 5, 2024
@alesrazym alesrazym changed the base branch from feature/kmm_rebased to develop June 5, 2024 09:17
@alesrazym alesrazym force-pushed the feature/kmm_konsist branch from 608b229 to 8c0e947 Compare June 5, 2024 09:18
@alesrazym alesrazym force-pushed the feature/kmm_konsist branch from a71b0fc to cf5abb4 Compare June 5, 2024 10:25
@alesrazym alesrazym force-pushed the feature/kmm_konsist branch from 53cbc18 to 23cb0d4 Compare June 11, 2024 10:56
@@ -0,0 +1,5 @@
package config

const val NAMESPACE_ID = "cz.quanti.rocketapp"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sloucil jsem const do build-logic, at se definuji jen jednou. Btw, build-logic uz je asi naming convention v gradle 8.5 a 8.8 https://docs.gradle.org/current/userguide/intro_multi_project_builds.html

apply(pluginId("kotlin-serialization"))
}
extensions.configure<ApplicationExtension> {
namespace = "$NAMESPACE_ID.$ANDROID_MODULE_ID"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rfc dle novych projektu

class ArchitectureLayersTest {
@Test
fun `clean architecture layers have correct dependencies`() {
// TODO handle MainApplication.kt
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jak resis main application, ktera zavisi na DI?

implementation(libs.library("test-coroutines"))

// Add SLF4J NOP to get rid of error message in ktor test.
implementation(libs.library("slf4j-nop"))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pridal jsem NOP logger, koukni, jestli neznas

}

android {
buildFeatures.buildConfig = true
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pres buildConfig predam hodnoty z build-logic

.apply {
assertArchitecture {
ArchitectureLayer.entries.forEach { layer ->
if (isLayerEmpty(layer)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trochu jsem to tu refaktoroval, koukni, jestli to dava smysl

import com.lemonappdev.konsist.api.architecture.Layer

enum class ArchitectureLayer(val layerName: String) {
/**
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pridal jsem commenty viz wiki

return Layer(name, "${PackagePatterns.ROOT_PACKAGE}..$layerName..")
}

fun ArchitectureLayer.dependencies(): List<ArchitectureLayer> = when (this) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

udelal jsem extension na dependencies, prijde mi to citelnejsi nez primo v testu. Nelze dat dependecy primo do enum, protoze je to cyklicka zavislost..

fun Konsist.appScope(): KoScope = scopeFromModules(modulesInScope)

fun Konsist.allScope(): KoScope = scopeFromProject()
.minus(Konsist.scopeFromModule("build-logic.*"))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mozna tohle jeste extrahovat

}
}

// TODO add tests for Repositories and domain models (Azure task number: 89759)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

co vsechno za testy chceme pridat?


import com.lemonappdev.konsist.api.architecture.Layer

enum class Module(val moduleType: ModuleType, val platform: Platform) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dal jsem dohromady modul a platform, at je to citelnejsi. Plus doc z wiki a dependency jako u layers

import cz.quanti.rocketapp.android.architecturetest.BuildConfig

object PackagePatterns {
const val ROOT_PACKAGE = BuildConfig.ROOT_PACKAGE
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tady to z build configu taham

import cz.quanti.rocketapp.android.architecturetest.BuildConfig

enum class Platform(val platformName: String) {
Android(BuildConfig.ANDROID_ID),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a tady taky

* so the caller is responsible for checking there is a message to show.
*/
@Composable
fun UiScreenState.Data<*>.ShowMessageInSnackBar() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevim, jestli je to idealni deleni, donutila me k tomu architektura - pouzivam zde localSnackbar ze system, a presentetion UiScreenState nemuze zaviset na system..

"${PackagePatterns.ANDROID_ID}.*",
)

fun Konsist.appScope(): KoScope = scopeFromModules(modulesInScope)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appScope predpoklada, ze neni zadny jinak pojmenovany modul

val arg = dependencies.first()
val args = dependencies.drop(1)
.toTypedArray()
thisLayer.dependsOn(arg, *args)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tohle je trochu divne, ze knihovna ma fci s parametry (X, vararg X ) nebo neco takoveho


private fun String.toModuleNameInPackage(): String {
return this
.replace('\\', '/')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

win stroje potrebuji zmenit lomitka

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants