B. *_*use 6 parameterized junit5
编写 JUnit 5 参数化测试,需要使用 Arguments.of() 将函数传递给测试,但有 2 个编译错误我不知道如何修复。任何帮助,将不胜感激。
public static Stream<Arguments> some() {
return Stream.of(Arguments.of(true, String::length));
}
@ParameterizedTest
@MethodSource
public <T> void some(final T input, final Function<String, Integer> length) {
}
Run Code Online (Sandbox Code Playgroud)
以下按预期工作。
public void sample() {
some(true, String::length);
}
Run Code Online (Sandbox Code Playgroud)
B. *_*use -1
该函数需要包装在一个类中。
public static class P {
private final Function<String, Integer> mFunction;
public P(final Function<String, Integer> function) {
mFunction = function;
}
public Function<String, Integer> function() {
return mFunction;
}
}
public static Stream<Arguments> some() {
return Stream.of(Arguments.of(3, "abc", new P(String::length)));
}
@ParameterizedTest
@MethodSource
public <T> void some(final int expect, final String input, final P p) {
assertEquals(expect, p.function().apply(input));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4960 次 |
| 最近记录: |