This simple unit test always passes and I can't figure out why.
@RunWith(JUnit4.class)
class SampleTest {
@Test testSomething() {
Uri uri = Uri.parse("myapp://home/payments");
assertTrue(uri == null);
}
}
What I have tried so far is using a "traditional" URI (http://example.com
) but uri
was also null
.
Check if you have the following in your app's gradle file:
android {
...
testOptions {
unitTests.returnDefaultValues = true
}
Uri
is an Android class and as such cannot be used in local unit tests, without the code above you get the following:
java.lang.RuntimeException: Method parse in android.net.Uri not mocked. See http://g.co/androidstudio/not-mocked for details.
The code above suppresses this exception and instead provides dummy implementations returning default values (null
in this case).
The other option is that you are using some framework in your tests that provides implementations of the methods in Android classes.