Status Update
Comments
hu...@google.com <hu...@google.com> #2
>> The same test passes in the app module
When I run ./gradlew :app:testDebugUnitTest, it fails with
java.lang.NullPointerException
at org.robolectric.android.internal.LocalActivityInvoker.startActivity(LocalActivityInvoker.java:36)
at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:207)
at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:184)
at net.rafaeltoledo.databindingbug.SampleTest.run(SampleTest.kt:14)
Can you double-check your sample project?
When I run ./gradlew :app:testDebugUnitTest, it fails with
java.lang.NullPointerException
at org.robolectric.android.internal.LocalActivityInvoker.startActivity(LocalActivityInvoker.java:36)
at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:207)
at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:184)
at net.rafaeltoledo.databindingbug.SampleTest.run(SampleTest.kt:14)
Can you double-check your sample project?
vf...@thoughtworks.com <vf...@thoughtworks.com> #3
Ah, sorry. I forgot to enable android resources for unit tests. Sample updated!
yb...@google.com <yb...@google.com> #4
i did just cloned and run :app:testDebugUnitTest and it worked w/o an error :/
wasn't it supposed to fail?
wasn't it supposed to fail?
vf...@thoughtworks.com <vf...@thoughtworks.com> #5
:app:testDebugUnitTest but :lib:app:testDebugUnitTest fails (they are exactly the same test). The problem seems to be related to library modules (I faced this issue when modularizing our project).
vf...@thoughtworks.com <vf...@thoughtworks.com> #6
BTW, I created a new branch in the same repository (without-kotlin) and the error occurs even without Kotlin. So, it seems to be related to library projects not running annotation processors for unit tests.
hu...@google.com <hu...@google.com> #7
@Rafael: Right, this is not related to Kotlin. I've looked at your sample project, annotation processing does run, it's just that the androidx.databinding.DataBinderMapperImpl is not generated for the library module (hence the NoClassDefFoundError).
@Yigit: I see this logic in CompilerChef:
final boolean generateMergedMapper;
if (compilerArgs.isApp()) {
generateMergedMapper = !compilerArgs.isTestVariant();
} else if (!compilerArgs.isFeature()) {
generateMergedMapper = compilerArgs.isTestVariant(); // <== This is why the class is missing in the library module, because compilerArgs.isTestVariant() evaluates to false
} else {
generateMergedMapper = false;
}
If we want to support Robolectric tests, we probably need to reconsider the definition of a test variant, or revise the above logic.
@Yigit: I see this logic in CompilerChef:
final boolean generateMergedMapper;
if (compilerArgs.isApp()) {
generateMergedMapper = !compilerArgs.isTestVariant();
} else if (!compilerArgs.isFeature()) {
generateMergedMapper = compilerArgs.isTestVariant(); // <== This is why the class is missing in the library module, because compilerArgs.isTestVariant() evaluates to false
} else {
generateMergedMapper = false;
}
If we want to support Robolectric tests, we probably need to reconsider the definition of a test variant, or revise the above logic.
yb...@google.com <yb...@google.com> #8
hmm seems like robolectric tests for libs should be compiled like apps not libs if they want to run independently.
thats what happens for androidTest instances for libs where it gets compiled like an app hence mapper is generated but only for androidTest, not the lib itself.
thats what happens for androidTest instances for libs where it gets compiled like an app hence mapper is generated but only for androidTest, not the lib itself.
yb...@google.com <yb...@google.com> #9
over to Hung to get verification. Maybe we are just setting up data binding wrong for unit tests on android if robolectric is using that infra.
Description
Example project:
How to reproduce:
Run ./gradlew testDebug
The same test passes in the app module, but fails in the lib module