Issue
I am running Android instrumentation tests on an emulator on Travis CI. The following test case invokes a helper method per method reference:
@Test
public void testGetLowEmissionZones_worksAtAll() {
// ...
lowEmissionZone.childZones.forEach(this::testChildZone);
// ...
}
private void testChildZone(@NonNull ChildZone childZone) {
// ...
}
When Travis CI executes this test it fails with a NoClassDefFoundError:
ContentProviderTest > testGetLowEmissionZones_worksAtAll[test(AVD) - 4.3.1] FAILED
java.lang.NoClassDefFoundError: -$$Lambda$ContentProviderTest$He_xH9TsDaN0tZU8EqFP1CuQyAM
at ContentProviderTest.testLowEmissionZone(ContentProviderTest.java:151)
If I change the method invocation then there is no error:
@Test
public void testGetLowEmissionZones_worksAtAll() {
// ...
for (ChildZone childZone : lowEmissionZone.childZones) {
testChildZone(childZone);
}
// ...
}
I tried both openjdk8 and oraclejdk8, both fail.
How can I continue using method references?
Solution
Probably, you are facing this issue because forEach(Consumer<?> consumer) is not available in Jelly Bean.
As you can see, the test is failling on 4.3.1. Ensure that this is related to API levels of the AVD. Ensure the code is working properly on API level 24 onwards.
Answered By - Nikola Despotoski
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.