Skip to content

Commit

Permalink
Updated README and renamed unit test method
Browse files Browse the repository at this point in the history
  • Loading branch information
LachlanMcKee committed Nov 20, 2017
1 parent e54d48f commit 4d39584
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4d39584

Please sign in to comment.