下面列出了org.junit.jupiter.params.aggregator.AggregateWith#org.junit.jupiter.params.provider.CsvFileSource 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@ParameterizedTest
@CsvFileSource(resources = "/input.csv")
void testWithCsvFileSource(String first, int second) {
System.out.println("Yet another parameterized test with (String) "
+ first + " and (int) " + second);
assertNotNull(first);
assertNotEquals(0, second);
}
@ParameterizedTest
@CsvFileSource(resources = "/input.csv")
void testWithCsvFileSource(String first, int second) {
System.out.println("Yet another parameterized test with (String) "
+ first + " and (int) " + second);
assertNotNull(first);
assertNotEquals(0, second);
}
@ParameterizedTest
@Disabled
@CsvFileSource(resources = "/org/jpeek/calculus/java/lcom4-params.csv")
public void calculatesValue(final String file, final String value) throws Exception {
final XML result = new Lcom4().node(
"", new HashMap<>(0), new Skeleton(
new FakeBase(file)
).xml()
);
new Assertion<>(
"Must create LCOM4 value",
new ItemAt<>(0, result.xpath("/metric/app/package/class/@value")),
new ScalarHasValue<>(value)
).affirm();
}
@ParameterizedTest
@CsvFileSource(resources = "/org/jpeek/metricstest-params.csv")
public void testsTarget(final String target, final String metric, final double value,
@TempDir final Path output)
throws Exception {
new XslReport(
new Skeleton(new FakeBase(target)).xml(), new XslCalculus(),
new ReportData(metric)
).save(output);
final String xpath;
if (Double.isNaN(value)) {
xpath = "//class[@id='%s' and @value='NaN']";
} else {
xpath = "//class[@id='%s' and number(@value)=%.4f]";
}
new Assertion<>(
new FormattedText(
"Must exists with target '%s' and value '%s'",
target, value
).asString(),
XhtmlMatchers.xhtml(
new TextOf(
output.resolve(String.format("%s.xml", metric))
).asString()
),
XhtmlMatchers.hasXPaths(
String.format(
xpath,
target, value
)
)
).affirm();
}
@ParameterizedTest
@CsvFileSource(resources = "/required-op-codes.csv")
void verifyCorrectOpCode(
final int opCode, @AggregateWith(MethodAggregator.class) final Method method) {
final RemoteActionCode remoteActionCode = method.getAnnotation(RemoteActionCode.class);
assertThat(
"Expected @RemoteActionCode annotation to be present for " + method,
remoteActionCode,
is(notNullValue()));
assertThat("Invalid value for " + method, remoteActionCode.value(), is(opCode));
}
@ParameterizedTest
@CsvFileSource(resources = "/dev-tags.csv")
void withCsvSource(String key, String value, Boolean outcome) {
Tag tag = Tag.builder().key(key).value(value).build();
assertEquals(outcome, devTagAnalyzer.isDevTagPresent(Arrays.asList(tag)));
}
@ParameterizedTest
@CsvFileSource(resources = "/country_code.csv", numLinesToSkip = 1)
void test_CsvFileSource(String country, int code) {
assertNotNull(country);
assertTrue(0 < code);
}
@ParameterizedTest
@CsvFileSource(resources = "/word-lengths.csv")
void withCsvFileSource(String word, int length) {
assertEquals(length, word.length());
}
@ParameterizedTest
@CsvFileSource(resources = "/normalizer/weirdToNormalizedUrls.csv")
void testBasicNormalizer(String weirdUrl, String expectedNormalizedUrl) throws Exception {
Assertions.assertEquals(expectedNormalizedUrl, normalizer.filter(weirdUrl), "normalizing: " + weirdUrl);
}