maven没有显示参数化测试的参数,有什么问题吗?

vkc1a9a2  于 2021-06-26  发布在  Java
关注(0)|答案(1)|浏览(527)

测试似乎运行得很好(有些测试失败了,但它们正在运行),但是日志没有显示参数,为什么?

@ExtendWith( SpringExtension.class )
@ContextConfiguration(
    locations = {
        "classpath:spring/testContext.xml",
        "classpath:applicationContext-mock.xml"
    } )
@Transactional
@ActiveProfiles( Profiles.TEST )
@Category( IntegrationTest.class )
public abstract class AbstractDalTestBase {
@ParameterizedTest
    @ArgumentsSource(LetterSearchWithFilterAndPagingForHCPCSCodeArguments.class)
    public void letterSearchWithFilterAndPagingForHCPCSCode(String searchTerm, int expected) {
        List<?> results = findMatchingItemsWithFilterAndPaging(searchTerm, CatalogItemType.HCPCSCODE, 0, 0, null);
        int projection = loadTotalNumberOfItems(searchTerm, CatalogItemType.HCPCSCODE);
        assertThat(projection).as("projection eq results").isEqualTo(results.size());
        assertThat(projection).as("projection eq expected").isEqualTo(expected);
        assertThat(results.size()).as("results eq expected").isEqualTo(expected);
    }
class LetterSearchWithFilterAndPagingForHCPCSCodeArguments implements ArgumentsProvider {

    @Override
    public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) {
        int count = 5643;
        return Stream.of(
            Arguments.of("A", count),
            Arguments.of("a"),
            Arguments.of("b", 2151)
        );
    }
}
[ThreadedStreamConsumer] ERROR org.apache.maven.plugin.surefire.SurefirePlugin - letterSearchWithFilterAndPagingForHCPCSCode{String, int}[1]  Time elapsed: 2.496 s  <<< FAILURE!
java.lang.AssertionError: 
[projection eq results] 
Expecting:
 <5643>
and actual:
 <5643>
to refer to the same object

我以为junit应该记录传递给方法的值,我怎么能让它这样做呢?

tp5buhyn

tp5buhyn1#

我找到了这张junit的票,问题是肯定的。它是固定在3.0.0-m5,不幸的是,我不能使用。
不使用显示名的基本原理是,它会“破坏”surefire生成的xml报告。因此,我们需要一种新的报告格式,surefire需要在报告显示名称之前采用这种格式(参见#373)。
由于插件版本3.0.0-m4,您可以使用报告的细粒度配置,并在测试中启用短语名称和@displayname。这是特定对象属性的完整列表。您不必指定例如禁用、版本和编码。如果未另行指定,布尔值将达到默认值false。

<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M5</version>
            <configuration>
                <statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
                    <disable>false</disable>
                    <version>3.0</version>
                    <usePhrasedFileName>false</usePhrasedFileName>
                    <usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
                    <usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
                    <usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
                </statelessTestsetReporter>
                <consoleOutputReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5ConsoleOutputReporter">
                    <disable>false</disable>
                    <encoding>UTF-8</encoding>
                    <usePhrasedFileName>false</usePhrasedFileName>
                </consoleOutputReporter>
                <statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoReporter">
                    <disable>false</disable>
                    <usePhrasedFileName>false</usePhrasedFileName>
                    <usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
                    <usePhrasedClassNameInTestCaseSummary>true</usePhrasedClassNameInTestCaseSummary>
                </statelessTestsetInfoReporter>
            </configuration>
        </plugin>
    </plugins>
</build>

相关问题