五流!!日曜プログラマーのつどい - JUnit4

JUnit4

Install

javadoc

Setting

Maven

Mavenでの指定を示す。またマッチャーのライブラリのであるhamcrest-libraryの依存関係も載せる。
<scope>はtestのときしか使用しないので[test]指定している。
<dependency>
	<groupId>junit</groupId>
	<artifactId>junit</artifactId>
	<version>4.11</version>
	<scope>test</scope>
</dependency>

<dependency>
	<groupId>org.hamcrest</groupId>
	<artifactId>hamcrest-library</artifactId>
	<version>1.3</version>
	<scope>test</scope>
</dependency>
<dependency>
	<groupId>org.hamcrest</groupId>
	<artifactId>hamcrest-core</artifactId>
	<version>1.3</version>
	<scope>test</scope>
</dependency>

Example

JUnit4 アサーション
 fail, assertThat

テストクラス
 @BeforeClass, @AfterClass, @Before, @After, @Test

テストスイート
 @RunWith(Suite.class), @SuiteClasses({Hoge.class, Piyo.class})

テストの構造化
 @RunWith(Enclosed.class)

パラメータテスト
 @RunWith(Theories.class), @DataPoint, @DataPoints, @Theory

カテゴリ化テスト
 @Category(Hoge.class), @RunWith(Categories.class),
 @IncludeCategory(Aho.class), @ExcludeCategory(Fuga.class),
 @SuiteClasses({Hoge.class, Piyo.class})

JUnit4 ルール
 @Rule, @RuleClass

参照URL

関連URL