您可以使用
JUnitParams
lib。
将xml和csv文件放入
/src/test/resources
项目文件夹(对maven/gradle项目有效)。
并在测试中使用它们,如下所示:
@RunWith(JUnitParamsRunner.class)
public class ServiceTest {
@Test
@Parameters({
"first.xml, first.csv",
"second.xml, second.csv",
"third.xml, third.csv"
})
public void shouldServe(String xmlFilePath, String csvFilePath) {
String xmlFileContent = readContent(xmlFilePath);
String csvFileContent = readContent(csvFilePath);
}
}
哪里
readContent
是从文本文件中读取内容的方法。