More Related Content
Similar to About junit (20)
More from エンジニア勉強会 エスキュービズム
More from エンジニア勉強会 エスキュービズム (20)
About junit
- 12. JUnitによるユニットテストのパ
ターン
• 1. 標準的な振る舞いの検証
• テストケース間で共通する初期化/後処理の記述
• @Before,@Afterアノテーションを付与したメソッド
• (若しくはsetUp(), tearDown())
• テストケース毎に毎回呼ばれる
• https://phpunit.de/manual/current/ja/
appendixes.annotations.html#appendixes.annotations.before
• https://github.com/shuji/practice-junit/blob/
b4674819f8bb59d63fbca1621cde6198f380c88d/junit-exercises/src/
test/java/ch18/ex03/CounterTest.java
- 13. JUnitによるユニットテストのパ
ターン
• 1. 標準的な振る舞いの検証
• テストケース間で共通する初期化/後処理の記述2
• @BeforeClass,@AfterClassアノテーションを付与したメソッド
• テストクラスの1つ目のテストメソッド実行前/すべてのテストメソッ
ド実行後に一度だけ呼ばれる
• https://phpunit.de/manual/current/ja/
appendixes.annotations.html#appendixes.annotations.beforeClass
• https://github.com/shuji/practice-junit/blob/
b4674819f8bb59d63fbca1621cde6198f380c88d/junit-examples/src/
test/java/ch03/BeforeClassAndAfterClassTest.java
- 14. JUnitによるユニットテストのパ
ターン
• 2. 例外送出検証
• 異常時に期待された例外がスローされるか検証
• アノテーションに期待する例外を記載
• phpunit => @expectedException
• https://phpunit.de/manual/current/ja/writing-tests-
for-phpunit.html#writing-tests-for-phpunit.exceptions
• https://phpunit.de/manual/current/ja/writing-tests-
for-phpunit.html#writing-tests-for-phpunit.exceptions
- 15. JUnitによるユニットテストのパ
ターン
• 3. コンストラクタの検証
• インスタンス生成後に正しくフィールドが初期化さ
れているか検証
• https://github.com/shuji/practice-junit/blob/
b4674819f8bb59d63fbca1621cde6198f380c88d/junit-
examples/src/test/java/ch03/
ConstructorTest.java