Android Unit test are giving wrong result

1.8k views Asked by At

When I run a unit test for a new created project then it shows me the wrong result (Says All Tests are passed).

If you see in the image below 4 is expected while 6+2 surely not 4.

enter image description here

Now when I run the same test from Gradle right menu. It shows me the correct result that test has failed.

enter image description here

Did I do anything wrong or is this an android studio bug?


Edit

Run configuration image

enter image description here

1

There are 1 answers

7
Lam On

You need to add -ea option in the "VM options" box in your 3rd image. This is to enable assertion feature for the JVM. Without this -ea, JVM just ignore assertion statement. When you run the test with gradle, it used a default configuration so that's why your test was run correctly.