Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1539)

Unified Diff: testing/android/docs/junit4.md

Issue 2864483004: Add more common errors to JUnit4 documentation (Closed)
Patch Set: address comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/android/docs/junit4.md
diff --git a/testing/android/docs/junit4.md b/testing/android/docs/junit4.md
index d40583fbe545490aef7c961bb61fb5b9526bc905..89baaaacec8cfc639fae7a0a90160c38ea1cc47f 100644
--- a/testing/android/docs/junit4.md
+++ b/testing/android/docs/junit4.md
@@ -146,24 +146,28 @@ public class MyRule implements TestRule {
```
-## Caveats
+## Common Errors
1. Instrumentation tests that rely on test thread to have message handler
will not work. For example error message:
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- Please utilize `@UiThreadTest` or
- `ActivityTestRule.runOnUiThread(Runnable r)` to refactor these tests.
- For more, check this [GitHub issue][6]
-
-1. Use `@UiThreadTest` with caution. Currently,
- **@UiThreadTest is only effective when UiThreadTestRule or
- ActivityTestRule is declared** in the test class. Please use
- `android.support.test.annotation.UiThreadTest`, not
- `android.test.UiThreadTest`. When using @UiThreadTest, **it would cause
- `setUp` and `tearDown` to run in Ui Thread** as well. Avoid that by simply
- calling [`runOnUiThread`][9] or [`runOnMainSync`][10] with a Runnable.
+ or
+
+ java.lang.IllegalStateException: The current thread must have a looper!
+
+ Please utilize `ActivityTestRule.runOnUiThread(Runnable r)` to refactor
+ these tests. For more, check this [GitHub issue][6]
+
+1. Use `@UiThreadTest` with caution!!
+ - Currently, **@UiThreadTest is only effective when UiThreadTestRule or
+ ActivityTestRule is declared** in the test class.
+ - Please use **`android.support.test.annotation.UiThreadTest`, NOT
+ `android.test.UiThreadTest`**.
+ - When using @UiThreadTest, **it would cause `setUp` and `tearDown` to
+ run in Ui Thread** as well. Avoid that by calling [`runOnUiThread`][9]
+ or [`runOnMainSync`][10] with a Runnable.
```java
// Wrong test
@@ -211,12 +215,19 @@ public class MyRule implements TestRule {
}
```
-
1. `assertEquals(float a, float b)` and `assertEquals(double a, double b)` are
deprecated in JUnit4's Assert class. **Despite only generating a warning at
build time, they fail at runtime.** Please use
`Assert.assertEquals(float a, float b, float delta)`
+1. Errorprone expects all public methods starting with `test...` to be
+ annotated with `@Test`. Failure to meet that expectation will cause
+ errorprone to fail with something like this:
+
+ [JUnit4TestNotRun] Test method will not be run; please add @Test annotation
+
+ In particular, you may see this when attempting to disable tests. In that
+ case, the test should be annotated with both @DisabledTest and @Test.
## Common questions
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698