Closed BulatMukhutdinov closed 6 years ago
To solve that you can enable returnDefaultValues
, like this:
android {
testOptions {
unitTests.returnDefaultValues = true
}
}
Of course first of all I tried this solution but it doesn't work. Have you another idea how to fix it?
Could you share a project with minimal reproducible sample?
https://github.com/BulatMukhutdinov/PitestExample
I created minimal structure to reproduce error
./gradlew testDebug
./gradlew pitest
OK, I'll check that ASAP.
Workaround is to add mock-maker-inline: https://github.com/koral--/PitestExample/commit/6ffdc0e081f278c46929a90581a83f2ef86d47cf
Now there is no previous exception and it even generates pitest report, but now I caught this
app/src/main/java/bulat/example/pitestexample/Pitest.java:16: error: cannot find symbol return context.getString(R.string.api_base_url); ^ symbol: variable api_base_url location: class string 1 error
Did you have this error?
cannot find symbol return context.getString(R.string.api_base_url)
That's because you defined resValue "string", "api_base_url", "http://192.168.0.1:8080"
inside debug
block only. https://github.com/BulatMukhutdinov/PitestExample/blob/master/app/build.gradle#L37 So pitestRelease
or pitest
task will fail due to this error but pitestDebug
will work.
I'll keep this issue open until some better solution to the 1st issue is found.
Hi! I am injecting Context through Dagger 2. On testing I am overriding component with providing context like this
@Provides @Singleton Context provideContext() { Context contextMock = mock(Context.class); when(contextMock.getString(R.string.api_base_url)).thenReturn("http://192.168.0.1:5632/api/v0_0_8/"); return contextMock; }
When running JUnit tests it works well - when calling context.getString() it returns what needed and test suite is green.
But when run pitest it says that
INFO : MINION : Exception: Stub! at android.content.Context.getString(Context.java:30) at jp.co.soramitsu.yuna.domain.injection.TestModule.provideContext(TestModule.java:83)
Please help to properly mock Context for pitest Thanks!