0

Reland "Android: Prevent new Robolectric shadows via an allowlist"

This reverts commit ac9decf100.

Reason for reland: Added @WrappedPath()

Original change's description:
> Revert "Android: Prevent new Robolectric shadows via an allowlist"
>
> This reverts commit 2392f37108.
>
> Reason for revert: Missed @WrappedPath, breaking running tests
> from non-output-directory CWD.
>
> Original change's description:
> > Android: Prevent new Robolectric shadows via an allowlist
> >
> > Bug: b/341267427
> > Change-Id: I7e02f3ef4ef69930579727735acdb40b0581622c
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5545930
> > Commit-Queue: Andrew Grieve <agrieve@chromium.org>
> > Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
> > Cr-Commit-Position: refs/heads/main@{#1303784}
>
> Bug: b/341267427
> Change-Id: I9a9eb119e8b6bb8aff845b9234741ddd9b56239f
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5554933
> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Auto-Submit: Andrew Grieve <agrieve@chromium.org>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Cr-Commit-Position: refs/heads/main@{#1303949}

Bug: b/341267427
Change-Id: Iaaf6de65f804060b8091aabbe92405817873312b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5554143
Commit-Queue: Patrick Noland <pnoland@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Patrick Noland <pnoland@chromium.org>
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1303996}
This commit is contained in:
Andrew Grieve
2024-05-21 20:09:24 +00:00
committed by Chromium LUCI CQ
parent 2119509784
commit f8a603ce1a
12 changed files with 311 additions and 13 deletions
build
styleguide/java
testing/android/junit

@ -345,11 +345,13 @@ In summary:
* Use real dependencies when feasible and fast. Use Mockitos `@Mock` most
of the time, but write fakes for frequently used dependencies.
* Do not use Robolectric Shadows for Chromium code. Instead, use
`setForTesting()` methods so that it is clear that test hooks exist.
* When `setForTesting()` methods alter global state, use
[`ResettersForTesting.register()`] to ensure that the state is reset
between tests. Omit resetting them via `@After` methods.
* Do not use Robolectric Shadows for Chromium code.
* Shadows make code harder to refactor.
* Prefer to refactor code to make it more testable.
* When you really need to use a test double for a static method, add a
`setFooForTesting() [...]` method to make the test contract explicit.
* Use [`ResettersForTesting.register()`] from within `ForTesting()`
methods to ensure that state is reset between tests.
* Use Robolectric when possible (when tests do not require native). Other
times, use on-device tests with one of the following annotations: