-
Changes in Version 3.6.2 (2021-01-22)
Changes in Version 3.5.0 (2020-06-04)
Changes in Version 3.4.2 (2020-03-26)
Changes in Version 3.3.1 (2019-08-22)
Changes in Version 3.3.0 (2019-01-09)
Changes in Version 3.2.1 (2018-12-21)
Changes in Version 3.2.0 (2018-08-27)
Changes in Version 3.1.1 (2018-06-29)
Changes in Version 3.1.0 (2018-03-27)
Changes in Version 3.0.0 (2018-02-20)
Test Class
In order to use test classes in your project, you need the tapir-execution module.
<dependency>
<groupId>de.bmiag.tapir</groupId>
<artifactId>tapir-execution</artifactId>
</dependency>
Structure
A test class (annotated with @TestClass) is an executable unit which contains at least one step. All the steps (annotated with @Step) declared in a test class are executed sequentially. The most simple test class looks like this:
@TestClass
class MyTest {
@Step
def void step1() {
println("Step 1 is executed")
}
}
Using Page Objects
Test classes should use page objects to interact with the SUT. Like any other Spring bean these page objects can be autowired by using Spring’s @Autowire annotation. You can find additional information about page objects in the dedicated chapter.
@TestClass
class MyTest {
@Autowired
MyPage myPage
@Step
def void step1() {
myPage.textField.text = "Test"
}
}
Extensions
In every Test class TapirAssertions is registered and all its visible members can be used in the test class:
@TestClass
class MyTest {
@Autowired
MyPage myPage
@Step
def void step1() {
assertThat(myPage.textField.text, is("Test"))
}
}
You can add custom extensions by using @UseExtension.
UseBean
You can use the annotation @UseBean to inject arbitrary beans into your test class. It adds the given bean classes under a default name as a field and adds Spring’s Autowired annotation. This works similar to @UseExtension, but does not add the new field as extension. This annotation is useful if you want to use multiple page objects in your test and don’t want to add each of them as a field.
@TestClass
@UseBean(MyPage)
class MyTest {
@Step
def void step1() {
assertThat(myPage.textField.text, is("Test"))
}
}
Documentation
Test classes can and should be documented. There is a dedicated chapter about Documentation.
- Previous
- Next