More Related Content
Similar to Javaアプリケーション開発におけるユニットテストとTDDの実践 Java Day Tokyo 2014
Similar to Javaアプリケーション開発におけるユニットテストとTDDの実践 Java Day Tokyo 2014 (20)
More from Shuji Watanabe (20)
Javaアプリケーション開発におけるユニットテストとTDDの実践 Java Day Tokyo 2014
- 3. 渡辺 修司 / @shuji_w6e
JUnit実践入門(技術評論社)
クラスメソッド株式会社
札幌にて在宅勤務
AWS関連
ポータルサイト構築
Spring, Ember.js, d3-data
4刷!
累計1万部
- 26. 4 Phase Test
初期化 ー Setup
テスト実行時の状態を一定にする
実行 ー Exercise
テスト実行後の影響を観測する
検証 ー Verify
期待する結果となるかを検証する
後処理 ー Teardown
次のテストへの影響させない
- 33. public class SampleTest extends DBTestCase {
protected void setUp() throws Exception {
super.setUp();
DatabaseOperation.CLEAN_INSERT
.execute(connection, dataSet);
}
public void testMe() throws Exception {
IDataSet databaseDataSet = getConnection().createDataSet();
ITable actualTable = databaseDataSet.getTable("TABLE_NAME");
IDataSet expectedDataSet = new FlatXmlDataSetBuilder()
.build(new File("expectedDataSet.xml"));
ITable expectedTable =
expectedDataSet.getTable("TABLE_NAME");
Assertion.assertEquals(expectedTable, actualTable);
}
}
- 35. public class UserRepositoryTest {
@Rule
public DbUnitTester tester = DbUnitTester
.forJdbc("com.mysql.jdbc.Driver",
"jdbc:mysql://localhost:3306/cmtest")
.username("root").password("").create();
@Fixture(resources = "2-users.yaml")
@Test
public void updateによる更新() throws Exception {
IDataSet expected = YamlDataSet
.load(getClass().getResourceAsStream("yaml"));
sut.update(user);
tester.verifyTable("users", expected);
}
}