【发布时间】:2019-06-24 12:42:28
【问题描述】:
我想用@ValueSource 做一个ParameterizedTest,我已经阅读了很多教程,包括Guide to JUnit 5 Parameterized Tests:
/**
* The {@link Class} values to use as sources of arguments; must not be empty.
*
* @since 5.1
*/
Class<?>[] classes() default {};
所以我尝试了以下方法:
@ParameterizedTest
@ValueSource(classes = {new Mandator("0052", "123456", 79)})
void testCalculateMandateI(Mandator value) {
//code using Mandator here
}
强制类:
public class Mandator {
private String creditorPrefix;
private String retailerCode;
private int mandateIdSequence;
public Mandator(final String creditorPrefix, final String retailerCode, final int mandateIdSequence) {
this.creditorPrefix = creditorPrefix;
this.retailerCode = retailerCode;
this.mandateIdSequence = mandateIdSequence;
}
public String getCreditorPrefix() {
return creditorPrefix;
}
public String getRetailerCode() {
return retailerCode;
}
public int getMandateIdSequence() {
return mandateIdSequence;
}
}
但我从 IntelliJ 收到以下错误,悬停在 @ValueSource 上方:
属性值必须是常数
我在这里做错了什么?我错过了什么?
【问题讨论】:
-
第一个解释了如何将 JUnit 与源代码一起使用。其他人解释了错误的原因,“属性值必须是常量”,您收到了。它们都是相关的。
标签: java junit5 parameterized