Reputation: 25874
This simple test
@RunWith(JUnit4::class)
class Test {
@Test
fun test() {
assert(false)
}
}
Unexpectedly, this passes when put in androidTest
(both through Android Studio and in the terminal), but obviously fails as expected when put in test
.
Upvotes: 1
Views: 1605
Reputation: 569
I just fall on same issue, on a newer version of junit
I then used quite the same code as accepted answer with org.junit.jupiter.api.Assertions.assertTrue(false)
but IntelliJ told me there is a simpler method with:
org.junit.jupiter.api.Assertions.fail();
Upvotes: 1
Reputation: 8227
You need to use JUnit assertions for running tests. The base assert()
functionality is normally disabled when running "production" code, so you cannot depend that a plain assert
statement will throw an assertion exception.
Use:
org.junit.Asserts.assertTrue( false )
to make the test fail properly.
Upvotes: 6