テストコードの構造 (Vision)
scenario と case
Shiratesでは JUnit 5のテストメソッドが自動テストのセッションに対応し、その中に1つの scenario と1つ以上の case を含みます。
サンプルコード
TestScenarioAndTestCase1.kt
(kotlin/tutorial_vision/basic/TestScenarioAndTestCase1.kt
)
@Test
@Order(10)
fun scenarioAndCase() {
scenario {
case(1) {
// TODO: implement action and expectation
}
case(2) {
// TODO: implement action and expectation
}
}
}
@Test
@Order(20)
fun caePattern() {
scenario {
case(1) {
condition {
it.screenIs("[Android設定トップ画面]")
}.action {
it.tap("ネットワークとインターネット")
}.expectation {
it.screenIs("[ネットワークとインターネット画面]")
}
}
}
}
テストを実行する
- Androidで実行されるように
testrun.global.properties
のos
を設定します (デフォルトはandroid
なので単にコメントアウトします)。
## OS --------------------
#os=ios
TestScenarioAndTestCase1
を右クリックしてDebug
を選択します。
condition-action-expectation (CAE)
case(テストケース)は以下のブロックの組み合わせです。
condition
(事前条件)action
(アクション)expectation
(期待結果)
TestScenarioAndTestCase1.kt
@Test
@Order(20)
fun caePattern() {
scenario {
case(1) {
condition {
it.screenIs("[Android設定トップ画面]")
}.action {
it.tap("ネットワークとインターネット")
}.expectation {
it.screenIs("[ネットワークとインターネット画面]")
}
}
}
}
このパターンはShiratesでは “CAE pattern” と呼びます。これは有名なUnitテストプラクティスの “AAAパターン ( Arrange-Act-Assert pattern)” に対応するものです。