Skip to content

Commit

Permalink
Add unit testing tips to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ellsworthrw committed Feb 19, 2025
1 parent 2de0599 commit 12d641d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
build
/captures
node_modules
kotlin-js-store
.externalNativeBuild
notes.txt
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,31 @@ KmLogging.setLoggers(PlatformLogger(FixedLogLevel(BuildConfig.DEBUG)))
reason so only a single boolean check will be done at runtime to minimize the overhead when
running in production. The android sample app demonstrates this.

## Use in unit testing

* If you want log messages to show up while unit testing then in your test class you can set up a
logger that prints to the console using something like:

```kotlin
@BeforeTest
fun setup() {
KmLogging.setLoggers(PrintLogger(FixedLogLevel(true)))
}
```

* On Android unit tests will complain about not supplying default values or not being mocked. You
will want to include the following:

```kotlin
android {
testOptions {
unitTests {
isReturnDefaultValues = true
}
}
}
```

## Logging to another system such as Crashlytics

If logging is only desired at certain levels that can be setup. For example, if only the more
Expand Down
14 changes: 6 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
Expand All @@ -8,20 +10,16 @@ plugins {
}

allprojects {
repositories {
google()
mavenCentral()
mavenLocal()
}

tasks.withType(JavaCompile::class.java).configureEach {
sourceCompatibility = "11"
targetCompatibility = "11"
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).configureEach {
kotlinOptions {
jvmTarget = "11"
compilerOptions {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}
}
}

0 comments on commit 12d641d

Please sign in to comment.