Skip to content

Instantly share code, notes, and snippets.

@mid0111
Created February 4, 2014 07:56
Show Gist options
  • Save mid0111/8799688 to your computer and use it in GitHub Desktop.
Save mid0111/8799688 to your computer and use it in GitHub Desktop.
JUnit4のData Driven Test
@RunWith(Enclosed.class)
@Category({Unit.class })
public class FooTest {
/**
* テスト用Fixture。
*/
static class Fixture {
String testComment;
/**
* 入力値.
*/
String inputValue;
/**
* 期待する返却値.
*/
String expectedReturnValue;
/**
* コンストラクタ.
* @param testComment テスト内容
* @param inputValue 入力値
* @param expectedReturnValue 期待する返却値
*/
Fixture(String testComment,
String inputValue,
String expectedReturnValue) {
this.testComment = testComment;
this.inputValue = inputValue;
this.expectedReturnValue = expectedReturnValue;
}
}
@RunWith(Theories.class)
public static class TestTheories {
/**
* テストパターンを作成.
* @return テストパターン
*/
@DataPoints
public static Fixture[] getFixture() {
Fixture[] datas = {
new Fixture("pochiがtamaになること", "pochi", "tama")
};
return datas;
}
/**
* テストシナリオ.
* @param f テストパターン
* @throws Exception Exception
*/
@Theory
public void 変換チェック(Fixture f) throws Exception {
Foo foo = new Foo();
String actual = foo.convert(f.inputValue);
assertEquals(f.testComment, f.expectedReturnValue, actual);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment