JUnit –テストを無視する
JUnitでは、テストを無視するには、@Test
メソッドの前後に@Ignore
アノテーションを追加するだけです。
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)がテストランナーに表示されます。