生成一个最完整的serenity junit程序
这里提供一个使用Serenity和JUnit5的最完整的示例程序:
- 首先需要在pom.xml中添加Serenity和JUnit5的依赖:
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>2.3.8</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
- 接着创建一个测试类,并在类上添加
@RunWith(SerenityRunner.class)注解,表示使用Serenity的Runner来运行测试。
@RunWith(SerenityRunner.class)
public class SampleTest {
// ...
}
- 在测试类中,可以定义测试方法,使用
@Test注解标记。
@Test
public void testSerenity() {
// ...
}
- 可以使用
@Step注解来定义测试步骤,这些步骤将在测试报告中展示。
@Step("Step 1: 打开首页")
public void openHomePage() {
// ...
}
@Step("Step 2: 输入用户名和密码")
public void enterUsernameAndPassword() {
// ...
}
@Step("Step 3: 点击登录按钮")
public void clickLoginButton() {
// ...
}
- 在测试方法中,可以调用测试步骤方法。
@Test
public void testSerenity() {
openHomePage();
enterUsernameAndPassword();
clickLoginButton();
}
- 可以使用
@Title注解来定义测试用例的标题,这些标题将在测试报告中展示。
@Title("测试登录功能")
@Test
public void testSerenity() {
openHomePage();
enterUsernameAndPassword();
clickLoginButton();
}
- 可以使用
@DisplayName注解来定义测试用例的显示名称,这些名称将在测试报告中展示。
@DisplayName("测试登录功能")
@Test
public void testSerenity() {
openHomePage();
enterUsernameAndPassword();
clickLoginButton();
}
- 最后,在测试类中添加
@Manual注解,表示这是一个手动测试用例,需要手动运行。
@Manual
@RunWith(SerenityRunner.class)
public class SampleTest {
// ...
}
这样,就完成了一个最完整的Serenity和JUnit5的测试程序。可以运行该测试程序,生成测试报告并查看
原文地址: https://www.cveoy.top/t/topic/cLva 著作权归作者所有。请勿转载和采集!