If you want to always intentionally fail a Java Junit test case then make use of the static fail() method from the org.junit.jupiter.api.Assertions class.
import static org.junit.jupiter.api.Assertions.fail;
public class TestJunit {
@Test
public void failTest() {
System.out.println("hello there!");
fail("This case will always fail!");
}
}
org.opentest4j.AssertionFailedError: This case will always fail!
at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:38)
at org.junit.jupiter.api.Assertions.fail(Assertions.java:135)
at TestJunit.failTest(TestJunit.java:11)
...
...
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!