Designing test in code first (Classic)
You can design test in code first style.
- Create test class, then create test functions with
@Manual
annotation. - Implement procedures of tests tentatively.
- After the app under test is rolled out, remove
@Manual
, implement tests completely, and run tests.
CodeFirst1.kt
Create test class, then create test method with @Manual
annotation.
@Testrun("testConfig/android/calculator/testrun.properties")
class CodeFirst1 : UITest() {
@Manual
@Test
@DisplayName("Start calculator")
fun A0010() {
scenario {
}
}
@Manual
@Test
@DisplayName("Add")
fun A0020() {
scenario {
}
}
@Manual
@Test
@DisplayName("Divide by zero")
fun A0030() {
scenario {
}
}
}
Spec-Report
CodeFirst2.kt
Implement procedures of tests tentatively.
The macro “[Calculator Main Screen]” is not required to be implemented at this point. The screen nickname file “[Calculator Main Screen]” also is not required to be implemented at this point.
@Testrun("testConfig/android/calculator/testrun.properties")
class CodeFirst2 : UITest() {
@Manual
@Test
@DisplayName("Start calculator")
fun A0010() {
scenario {
case(1) {
condition {
it.macro("[Calculator Main Screen]")
}.expectation {
it.screenIs("[Calculator Main Screen]")
}
}
}
}
@Manual
@Test
@DisplayName("Add")
fun A0020() {
scenario {
case(1) {
condition {
it.macro("[Calculator Main Screen]")
}.action {
it.tap("[1]")
.tap("[+]")
.tap("[2]")
.tap("[=]")
}.expectation {
it.select("[result final]")
.textIs("3")
}
}
}
}
@Manual
@Test
@DisplayName("Divide by zero")
fun A0030() {
scenario {
case(1) {
condition {
it.macro("[Calculator Main Screen]")
}.action {
it.tap("[1]")
.tap("[÷]")
.tap("[0]")
.tap("[=]")
}.expectation {
it.select("[result preview]")
.textIs("Can't divide by 0")
}
}
}
}
}
You can run test, get Spec-Report as follows at this point.
Spec-Report
CodeFirst3.kt
After the test target app is rolled out, remove @Manual
, implement tests completely, and run tests.
@Testrun("testConfig/android/calculator/testrun.properties")
class CodeFirst3 : UITest() {
@Test
@DisplayName("Start calculator")
fun A0010() {
scenario {
case(1) {
condition {
it.macro("[Calculator Main Screen]")
}.expectation {
it.screenIs("[Calculator Main Screen]")
}
}
}
}
@Test
@DisplayName("Add")
fun A0020() {
scenario {
case(1) {
condition {
it.macro("[Calculator Main Screen]")
}.action {
it.tap("[1]")
.tap("[+]")
.tap("[2]")
.tap("[=]")
}.expectation {
it.select("[result final]")
.textIs("3")
}
}
}
}
@Test
@DisplayName("Divide by zero")
fun A0040() {
scenario {
case(1) {
condition {
it.macro("[Calculator Main Screen]")
}.action {
it.tap("[1]")
.tap("[÷]")
.tap("[0]")
.tap("[=]")
}.expectation {
it.select("[result preview]")
.textIs("Can't divide by 0")
}
}
}
}
}
If tests and the app are implemented correctly, you can get Spec-Report as follows.