diff --git a/README.md b/README.md index 72162bf..f7f0e3a 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,15 @@ 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: ```java public class TestExample { @Rule - public TimberTestRule mTimberTestRule = TimberTestRule.builder() + public TimberTestRule timberTestRule = TimberTestRule.builder() .minPriority(Log.ERROR) .showThread(true) .showTimestamp(false) @@ -17,6 +19,21 @@ public class TestExample { } ``` +There are also several factory methods which cover many common cases. These are: + +```java +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. diff --git a/timber-junit-sample/src/test/java/net/lachlanmckee/timberjunit/sample/LogTestWithOnlyOnTestFailure.java b/timber-junit-sample/src/test/java/net/lachlanmckee/timberjunit/sample/LogTestWithOnlyOnTestFailure.java index 859b806..de3f2a6 100644 --- a/timber-junit-sample/src/test/java/net/lachlanmckee/timberjunit/sample/LogTestWithOnlyOnTestFailure.java +++ b/timber-junit-sample/src/test/java/net/lachlanmckee/timberjunit/sample/LogTestWithOnlyOnTestFailure.java @@ -34,7 +34,7 @@ public static void setupConsoleOutput() { } @Test - public void given_when_then() throws InterruptedException { + public void deliberatelyFailingUnitTest() throws InterruptedException { LogTester.log(LogTester.LogType.ERROR, "Test"); expectedException.expect(AssertionError.class);