0

[doc] logging: explain how to enable it in junit tests

BUG=

Review URL: https://codereview.chromium.org/1581983002

Cr-Commit-Position: refs/heads/master@{#370682}
This commit is contained in:
dgn
2016-01-21 05:38:57 -08:00
committed by Commit bot
parent 435741872d
commit 0325c0f758
2 changed files with 21 additions and 1 deletions
base/android/java/src/org/chromium/base
docs

@ -17,7 +17,7 @@ import java.util.Locale;
* the origin of logs, and enable or disable logging in different parts of the code.
* </p>
* <p>
* Usage documentation: {@code //docs/logging.md}.
* Usage documentation: {@code //docs/android_logging.md}.
* </p>
*/
public class Log {

@ -206,3 +206,23 @@ further.
For more, see the [related page on developer.android.com]
(http://developer.android.com/tools/debugging/debugging-log.html#filteringOutput)
## Logs in JUnit tests
We use [robolectric](http://robolectric.org/) to run our JUnit tests. It
replaces some of the Android framework classes with "Shadow" classes
to ensure that we can run our code in a regular JVM. `android.util.Log` is one
of those replaced classes, and by default calling `Log` methods doesn't print
anything.
That default is not changed in the normal configuration, but if you need to
enable logging locally or for a specific test, just add those few lines to your
test:
```java
@Before
public void setUp() {
ShadowLog.stream = System.out;
//you other setup here
}
```