【发布时间】:2020-10-28 11:50:39
【问题描述】:
我需要将多个文件一个一个地传递给下面的 BeforeAll 方法。我可以通过重复相同代码的不同测试类来实现它。我想使用单个类对其进行优化。
@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);
}
请任何人建议实现这一目标?
参考 How to pass a Input and Expected file name dynamically for BeforeAll Method | Junit 5
【问题讨论】:
标签: java spring-boot unit-testing junit junit5