JUnit - игнорировать тест
В JUnit, чтобы игнорировать тест, просто добавьте аннотацию@Ignore
до или после метода@Test
.
P.S Tested with JUnit 4.12
IgnoreTest.java
package com.example; import org.junit.Ignore; import org.junit.Test; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; public class IgnoreTest { @Test public void testMath1() { assertThat(1 + 1, is(2)); } @Ignore @Test public void testMath2() { assertThat(1 + 2, is(5)); } @Ignore("some one please create a test for Math3!") @Test public void testMath3() { //... } }
В приведенном выше примере будут проигнорированы какtestMath2()
, так иtestMath3()
.
FAQS
1. Чтобы игнорировать тест, почему бы просто не прокомментировать методы тестирования или аннотацию@Test
?
A : The test runner will not report the test. In IDE, the test runner will display the ignored tests with different icon or color, and highlight it, so that you know what tests are ignored.
2. Зачем делать тест, который не тестирует?
A : For large project, many developers are handling different modules, the failed test may caused by other teams, you can add @Ignore
on the test method to avoid the test to break the entire build process.
A: Или вы хотите, чтобы кто-то помог создать тест, например@Ignore ("help for this method!")
, необязательный параметр (String) будет отображаться в средстве выполнения теста.