AspiringMat
AspiringMat

Reputation: 2269

Spring Boot passes test case that should fail

I have added a test case in my Spring Boot application. However, when I ./gradlew build, all the test cases pass. Any reason?

@Test
public void testIntentionalError() throws Exception {
    boolean thrown = true;
    assertThat(!thrown);
}

Upvotes: 2

Views: 778

Answers (2)

Amazia Gur
Amazia Gur

Reputation: 1712

you can try something like the following (in case you want to use the assertThat method):

@Test
public void testIntentionalError() throws Exception {
    boolean thrown = true;
    assertThat(!thrown, is(true));
}

using hamcrest matcher (import static org.hamcrest.core.Is.is)

Upvotes: 1

Sébastien Temprado
Sébastien Temprado

Reputation: 1463

It's because your test doesn't test anything.

Try this :

@Test
public void testIntentionalError() throws Exception {
    boolean thrown = true;
    assertTrue(!thrown);
}

Upvotes: 4

Related Questions