Timber-JUnit-Rule

JUnit TestRule that pipes Android Timber logs to the standard console

License

License

Categories

Categories

JUnit Unit Testing Net
GroupId

GroupId

net.lachlanmckee
ArtifactId

ArtifactId

timber-junit-rule
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

aar
Description

Description

Timber-JUnit-Rule
JUnit TestRule that pipes Android Timber logs to the standard console
Project URL

Project URL

https://github.com/LachlanMcKee/timber-junit-rule
Source Code Management

Source Code Management

https://github.com/LachlanMcKee/timber-junit-rule

Download timber-junit-rule

How to add to project

<!-- https://jarcasting.com/artifacts/net.lachlanmckee/timber-junit-rule/ -->
<dependency>
    <groupId>net.lachlanmckee</groupId>
    <artifactId>timber-junit-rule</artifactId>
    <version>1.0.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/net.lachlanmckee/timber-junit-rule/
implementation 'net.lachlanmckee:timber-junit-rule:1.0.1'
// https://jarcasting.com/artifacts/net.lachlanmckee/timber-junit-rule/
implementation ("net.lachlanmckee:timber-junit-rule:1.0.1")
'net.lachlanmckee:timber-junit-rule:aar:1.0.1'
<dependency org="net.lachlanmckee" name="timber-junit-rule" rev="1.0.1">
  <artifact name="timber-junit-rule" type="aar" />
</dependency>
@Grapes(
@Grab(group='net.lachlanmckee', module='timber-junit-rule', version='1.0.1')
)
libraryDependencies += "net.lachlanmckee" % "timber-junit-rule" % "1.0.1"
[net.lachlanmckee/timber-junit-rule "1.0.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Timber JUnit-Rule

This library provides a JUnit TestRule that plants a temporary Timber tree that 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.

Usage

Using the library is very straight forward. An example is as follows:

public class TestExample {
    @Rule
    public TimberTestRule timberTestRule = TimberTestRule.builder()
            .minPriority(Log.ERROR)
            .showThread(true)
            .showTimestamp(false)
            .onlyLogWhenTestFails(true)
            .build();
}

There are also several factory methods which cover many common cases. These are:

public class TestExample {
    @Rule
    public TimberTestRule logAllAlwaysRule = TimberTestRule.logAllAlways();
    @Rule
    public TimberTestRule logAllOnFailuresRule = TimberTestRule.logAllWhenTestFails();
    @Rule
    public TimberTestRule logErrorsAlwaysRule = TimberTestRule.logErrorsAlways();
    @Rule
    public TimberTestRule logErrorsOnFailuresRule = TimberTestRule.logErrorsWhenTestFails();
}

Configuration

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.

Download

This library is available on Maven, you can add it to your project using the following gradle dependencies:

testCompile 'net.lachlanmckee:timber-junit-rule:1.0.1'

Versions

Version
1.0.1
1.0.0