【发布时间】:2017-12-01 18:07:32
【问题描述】:
我们的自动化框架是用 Java 编写的并使用 Testng。我们使用@Test 注释来标记我们的测试,并为我们用 Gherkin 编写的测试提供组和描述。我们使用 Serenity 创建的测试报告
我一直在尝试创建一个静态常量类,我们可以使用它来构建测试描述,以便它处理 HTML 标记,而不是将其放入 String 本身,这样它更易于阅读,因此任何 HTML 格式测试报告的使用可以在这个类中完成,而不是每个
例如:
@Test( groups = { TestGroup.One, TestGroup.TWO }, description =
"<b>Given</b> I am in Scenario One</br>" +
"<b>When</b>I do something</br>" +
"<b>Then</b>I get a result")
protected void testScript() {
...
}
实际上看起来像:
@Test( groups = { TestGroup.One, TestGroup.TWO }, description =
TestDescription
.given("I am in Scenario One")
.when("I do something")
.then("I get a result");)
protected void testScript() {
...
}
我目前拥有的代码:
public final class TestDescription {
private static String description = "";
public static String given(final String given) {
return "<b>Given</b>" + given + "</br>";
}
public static TestDescription when(final String when) {
description = description + "<b>When</b>" + when + "</br>";
return null;
}
public static TestDescription then(final String then) {
description = description + "<b>Then</b>" + then + "</br>";
return null;
}
public static TestDescription and(final String and) {
description = description + "<b>And</b>" + and + "</br>";
return null;
}
public static String build() {
return description;
}
}
【问题讨论】:
-
你有什么问题?