【发布时间】:2020-07-06 06:31:11
【问题描述】:
我已经实现了一个测试用例来检查输入和预期的 Json 文件是否相同。
@BeforeAll
static void setUp() throws IOException {
inputList = readInput(CommonTestConstants.FilePath + "/Input1.json");
expectedList = readExpected(CommonTestConstants.FilePath + "/Expected1.json");
assertEquals("Checking size of both list",
inputList.size(), expectedList.size());
}
static Stream<Arguments> Arguments() {
return IntStream.range(0, inputList.size())
.mapToObj(i -> Arguments.of(inputList.get(i), expectedList.get(i)));
}
@ParameterizedTest
@DisplayName("Parameterized Test For First Input")
@MethodSource("Arguments")
void testFact(Object object, ExpectedObject expected) throws Exception {
Outcome outcome = processExpectedJson(object);
assertEquals(expected, outcome);
}
为了传递不同的文件名,我创建了类似上面的新测试类和测试方法。它按预期工作。现在为了更好的配置,我计划在单节课中实现它。通过从单个类动态传递输入和预期的 Json 不同文件,例如 Input2.json Expected2.json。
我需要将每个文件名作为参数传递给BeforeAll方法(Like looping),类似于参数化测试。
任何人都可以建议实现这一目标?
【问题讨论】:
标签: java unit-testing junit junit5 parameterized