This is actually a new behavior/feature in 2.4.
First, lint only runs some lint checks on test sources -- specifically, those that indicate that they apply to tests.
There's only one such check in the builtin set of checks: The unused resource check. If that one didn't look at test code at all, then lint would tell you a resource was unused, and you'd delete it, and then your build would fail.
Similarly, if you write a specific check that apply to tests (such as your scenario), obviously you'd want that check to look at the test files!
The way you do this is by adding the TEST scope to your issue:
new Implementation(
UnusedResourceDetector.class,
EnumSet.of(Scope.MANIFEST, Scope.ALL_RESOURCE_FILES, Scope.ALL_JAVA_FILES,
Scope.BINARY_RESOURCE_FILE, Scope.TEST_SOURCES));
However, it's possible that some users actually want to have all the checks apply to their tests too. If they want that, they can opt into it with this lint option in build.gradle:
android {
lintOptions {
checkTestSources false
}
}
With that set, lint will behave as in previous versions -- all checks will be run through all source files.
(By the way, there's a similar change for generated sources; lint no longer looks at those -- there's no way to opt an individual detector in (is there a use case for this?), but if you want to run lint checks on all generated source you can do that with lint option "checkGeneratedSources true".)
HOWEVER: The discrepancy between test/ and androidTest/ you discovered was not intentional -- that was a bug. I've just fixed that (as well as another problem where the wrong detectors were passed to the UAST visitor for test sources).
I've fixed both problems, and they'll be included in preview 8. Thanks for bringing this up!
-- Tor