Created
February 4, 2014 07:56
-
-
Save mid0111/8799688 to your computer and use it in GitHub Desktop.
JUnit4のData Driven Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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