x Java Java 8 JUnit JSON
  • XML
  • JDBC Spring Boot Microservices React Contact Us

    JUnit 5 Disable Tests

    Sometimes you may want to skip or disable a JUnit test, this can be done using @Disabled annotation. @Disabled annotation accepts the value parameter, in which you can provide the message why you skipped this test

    Disable an individual JUnit test using @Disabled annotation

    public class User {    private String name;    public User(String name) {        this.name = name;    }    public String getName() {        return this.name;    }}

    import org.junit.jupiter.api.Disabled;public class UserTest {    @Disabled (value = "skipping this test for now")    public void testUserNameIsNotNull() {        User user = new User("Nicolas Cage");        assertNotNull(user);    }        @Test    public void testUserNameIsNotEmpty() {        User user = new User("Nicolas Cage");        assertTrue(user.getName().length() > 0);    }}   

    Disable all JUnit tests using @Disabled annotation

    You can also disable all JUnit tests by using @Disabled annotation at Class level as shown below.

    @Disabled(value = "skipping all tests for now")public class UserTest {        // Junits }

    Comments

    Leave a Reply

    Your email address will not be published. Required fields are marked *











    Share This