问题描述
我正在尝试从CSV文件运行参数化测试。
如果我只使用CSVSource,那是可行的:
@ParameterizedTest
@CsvSource({ "a,A","b,B" })
void csvSourceTest(String input,String expected) {
String actualValue = input.toupperCase();
assertEquals(expected,actualValue);
}
但是,如果我从文件中尝试相同的操作,将无法正常工作
@ParameterizedTest
@CsvFileSource(resources = "/data.csv")
void csvFileSourceTest(String input,actualValue);
}
我也尝试过使用硬路径访问文件,但是对于Eclipse中的文件测试,我总是会收到消息
未找到测试运行器'JUnit 5'的测试。
JUnit在哪里期望文件?
这些是我的依赖项:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
有人知道我可能会缺少什么或者错误在哪里吗?
预先感谢
保罗
解决方法
JUnit5 user guide指出CSV文件必须位于类路径中。如果是Maven项目,则为const overdue = [{ "user.employeeId": "10001440","objectives": [ "Understand the financial indexes." ] },{ "user.employeeId": "10000303","objectives": [ "Document preparation & writing skills" ] },{ "user.employeeId": "10002168","objectives": [ "Chia ratio setting for Fuze Tea products L11" ] },"objectives": [ "Brix parameter differences between Processing and Production of Fuze Tea Lemon-Lemongrass standardization" ] },"objectives": [ "Paramix Line 9 setting parameter standardization" ] },];
const group = (arr,key) => Array.from(arr.reduce((m,obj) =>
m.set(
obj[key],{...obj,objectives: [...(m.get(obj[key])?.objectives ?? []),...obj.objectives]}
),new Map).values()
);
console.log(group(overdue,"user.employeeId"));
。