My Unit tests are failing with Method d in android.util.Log not mocked but only when I run testDebug. If running testRelease all is fine and they correctly pass. Does anyone know why this is happening? Same thing happens when running gradle from console and Android studio.
Junit: It is a “Unit Testing” framework for Java Applications. It is an automation framework for Unit as well as UI Testing.
Unit tests or small tests only verify a very small portion of the app, such as a method or class. End-to-end tests or big tests verify larger parts of the app at the same time, such as a whole screen or user flow. Medium tests are in between and check the integration between two or more units.
Here is an explanation how I solved this for future reference. Problem with tests working in debug but not release were due to a fact that Log.d (and friends from android framework) were not correctly mocked. Reason for it working when built as release is that our loging was conditional based on this property from build config. Basically we have if (BuildConfig.type!="Release") Log.d (...) and since the compiler removes this block due to final value it doesn't get called when testing release. To mock static method Log.d I used PowerMock. Mocking was easy but setting up Power Mock is really a hassle so there might probably be beter ways to do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With