使用 Serenity 报告的参数化 Junit 测试
Parametrized Junit tests with Serenity reports
我 运行 在测试 Spring 应用程序时遇到了一些麻烦。我团队目前的方法是在 Gherkin 中编写场景并让 Serenity 提供漂亮的报告。
应用中的新组件将需要大量测试用例。这些要求将在几个 'parsable' excel 文件中提供,所以我认为在 Junit 参数化测试中直接逐行直接使用它们会很整洁。另一种选择是编写一个臃肿的 Gherkin 功能,然后繁琐地手动编写每个示例。
所以我想到了类似的东西:
@RunWith(Parameterized.class)
private static class Tests {
@Parameterized.Parameters(name = "...") // name with the params
public static Collection params() {
// parse excel here or use some other class to do it
}
@Test
public void test() {
/* do the actual test - it involves sending and receiving some JSON objects */
}
}
这很顺利,但我 运行 在尝试使用时遇到了麻烦
@RunWith(SerenityRunner.class)
问题是 Junit 不支持多个 运行ners。我找到的一个解决方案是制作一个嵌套的 class 并用不同的 运行ner 注释每个,但我不知道如何让它工作(哪个 运行ner 应该在在外面,我实际上在哪里 运行 测试等等)。
有什么想法吗?
实际上 Serenity 提供了另一个运行器 - SerenityParameterizedRunner
,它似乎具有与 JUnit 的 Parameterized
相同的功能。
我 运行 在测试 Spring 应用程序时遇到了一些麻烦。我团队目前的方法是在 Gherkin 中编写场景并让 Serenity 提供漂亮的报告。
应用中的新组件将需要大量测试用例。这些要求将在几个 'parsable' excel 文件中提供,所以我认为在 Junit 参数化测试中直接逐行直接使用它们会很整洁。另一种选择是编写一个臃肿的 Gherkin 功能,然后繁琐地手动编写每个示例。
所以我想到了类似的东西:
@RunWith(Parameterized.class)
private static class Tests {
@Parameterized.Parameters(name = "...") // name with the params
public static Collection params() {
// parse excel here or use some other class to do it
}
@Test
public void test() {
/* do the actual test - it involves sending and receiving some JSON objects */
}
}
这很顺利,但我 运行 在尝试使用时遇到了麻烦
@RunWith(SerenityRunner.class)
问题是 Junit 不支持多个 运行ners。我找到的一个解决方案是制作一个嵌套的 class 并用不同的 运行ner 注释每个,但我不知道如何让它工作(哪个 运行ner 应该在在外面,我实际上在哪里 运行 测试等等)。
有什么想法吗?
实际上 Serenity 提供了另一个运行器 - SerenityParameterizedRunner
,它似乎具有与 JUnit 的 Parameterized
相同的功能。