Test code structure (Vision)
scenario and case
In Shirates, a JUnit 5 test method is an autotest session that includes a scenario and one or more test cases.
Sample code
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 Settings Top Screen]")
}.action {
it.tap("Network & internet")
}.expectation {
it.screenIs("[Network & internet Screen]")
}
}
}
}
Running test
- Set
os
intestrun.global.properties
to run as android (default is android).
## OS --------------------
#os=ios
- Right-click on the
TestScenarioAndTestCase1
and selectDebug
.
condition-action-expectation (CAE)
A test case is a combination of these blocks.
condition
action
expectation
TestScenarioAndTestCase1.kt
@Test
@Order(20)
fun caePattern() {
scenario {
case(1) {
condition {
it.screenIs("[Android Settings Top Screen]")
}.action {
it.tap("Network & internet")
}.expectation {
it.screenIs("[Network & internet Screen]")
}
}
}
}
This pattern is Shirates’s “CAE pattern”, like well known unit testing practice “AAA pattern (Arrange-Act-Assert pattern)”.