Junit Ignore Test

We designed a lot of some cases which test software behavior, however, some of them might be exceptions which run into problem or even not ready to test, we’d like to ignore or skip these cases but keep no-changes to existing code base. Annotation @ignore in JUnit 4 allows a test to be differed until it is ready (or the feature is).

1. Annotate Ignored for a test class, the Junit engine will bypass all test cases within this class

PersonTest.java
@Ignore("not today")
public class PersonTest extends  Assert {

  @Test
  public void getName() {
    assertEquals(person.getName(),  "Jammy");
  }

  @Test
  public void getAge() {
    assertEquals(person.getAge(),  6);
  }
}

2. Annotate “Ignored” for test method, the Junit engine will only bypass current test method

PersonTest.java
public class PersonTest extends  Assert {
  @Ignore("not today")
  @Test
  public void getName() {
    assertEquals(person.getName(),  "Jammy");
  }

  public void getAge() {
    assertEquals(person.getAge(),  6);
  }
}

Оцените статью
ASJAVA.COM
Добавить комментарий

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

*

code