如何解决如何使用JUnit5参数化测试CSV文件源?
我正在尝试从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"));
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。