This library provide a Kotlin written JUnit5 Extension for tests that plants a temporary Timber tree. It pipes any logs sent via Timber to the standard System.out. Once a unit test has completed, the Timber tree is removed to avoid logging unintended test cases.
The rule is extremely useful for Android JUnit tests, as the Timber logs do not show without planting a tree.
If you want to use library in default configuration it's extreamly easy:
@ExtendWith(TimberTestExtension::class)
class DefaultParametersTest {You can also provide your own configutation
class CustomParametersTest {
@JvmField
@RegisterExtension
val testExtension = TimberTestExtension(
Rules(
minPriority = Log.ERROR,
showThread = true,
showTimestamp = true,
logOnlyWhenTestFails = true
)
)
}As seen in the example above, there are many ways to modify the output using the following behaviours:
- The minimum log level to output.
- Whether thread ids are shown.
- Whether timestamps are shown.
- Whether to always log, or only log when a unit test fails.
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}dependencies {
testImplementation 'com.github.thecodeside:timber-junit5-extension:1.0.1'
}Special thanks to Lachlan McKee who created the original version of this library for JUnit4. I only rewrote it in Kotlin for JUnit5. You can find JUnit4 TestRule here version: https://github.com/LachlanMcKee/timber-junit-rule