Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Junit5参数化测试尝试时未找到匹配的Java异常测试_Java_Junit5_Parameterized Tests - Fatal编程技术网

Junit5参数化测试尝试时未找到匹配的Java异常测试

Junit5参数化测试尝试时未找到匹配的Java异常测试,java,junit5,parameterized-tests,Java,Junit5,Parameterized Tests,因此,我尝试使用JUnit5中的ParameterizedTest并设置pom来加载所有内容,现在有了下面的测试类 import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import ja

因此,我尝试使用JUnit5中的ParameterizedTest并设置pom来加载所有内容,现在有了下面的测试类

    import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import com.tdameritrade.ctg.cashmovement.enums.transaction.TransactionProcessEnum;
import com.tdameritrade.ctg.cashmovement.enums.transaction.TransactionStatusEnum;
import com.tdameritrade.ctg.junit.categories.UnitTest;

/**
 * Test class for Posting Common Utils
 */
@RunWith(JUnitPlatform.class)
@Category(UnitTest.class)
public class PostingCommonUtilsTest {

    private static Stream<Arguments> dataSetForTransactionStatus() {
        return Stream.of(Arguments.of(TransactionStatusEnum.ERRORED.getName(), true),
                         Arguments.of(TransactionStatusEnum.COMPLETED.getName(), false));
    }

    /**
     * Test method for
     * {@link com.tdameritrade.ctg.cashmovement.posting.PostingCommonUtils#checkTransactionErrored(java.lang.String)}.
     */
    @ParameterizedTest
    @MethodSource("dataSetForTransactionStatus")
    public void testCheckTransactionErrored(final String status, final boolean result) throws Exception {
        assertThat(PostingCommonUtils.checkTransactionErrored(status), is(equalTo(result)));
    }
}
也许我错过了,但我已经尝试搜索这个错误,我找到的所有东西都指向已经设置好的东西。例如,一篇文章说pom不在一起,但我有他们做的同样的事情

这是我的pom.xmls:

父POM:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
...  
      <properties>
...
        <junit.version>4.12</junit.version>
        <junit.platform.version>1.3.2</junit.platform.version>
        <junit.jupiter.version>5.3.2</junit.jupiter.version>
    </properties>

...
</project>

从堆栈跟踪来看,您似乎正在尝试使用
org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader
启动JUnit5测试。这不太可能奏效,同样的问题

尝试从命令行使用Maven运行测试,如文档中所述:

如果测试成功运行,或者您看到与Eclipse中完全相同的异常,那么您的Eclipse设置是正确的,这是框架的问题。否则,您的Eclipse设置是有缺陷的,不支持JUnit5

这可能是Eclipse版本的问题。根据官方网页:

我们不支持在旧的Eclipse构建(不支持JUnit5)使用新的Eclipse构建(支持JUnit5)作为目标的设置中运行测试。此外,拥有JDT JUnit运行时捆绑包(org.eclipse.JDT.JUnit.runtime,org.eclipse.JDT.junit4.runtime)的开发人员签出并获取最新更改时,将遇到上述问题。您需要使用新的Eclipse构建进行开发


对于JUnit5,您需要使用
@ExtendWith
而不是测试类下的
@RunWith

因此我使用的是Eclipse 4.5.2.No。它是“未能执行目标org.apache.maven.plugins:maven surefire plugin:2.12.4:test”@PatrickAquilone,因为您需要Eclipse4.7.1或4.8或更高版本的JUnit5支持。请提供带有根本原因的完整堆栈跟踪。这是不可能猜到的。在原始问题中添加了堆栈跟踪,因为它不适合这里。尽管可能只是因为我的Eclipse还不够晚
    import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import com.tdameritrade.ctg.cashmovement.enums.transaction.TransactionProcessEnum;
import com.tdameritrade.ctg.cashmovement.enums.transaction.TransactionStatusEnum;
import com.tdameritrade.ctg.junit.categories.UnitTest;

/**
 * Test class for Posting Common Utils
 */
@RunWith(JUnitPlatform.class)
@Category(UnitTest.class)
public class PostingCommonUtilsTest {

    private static Stream<Arguments> dataSetForTransactionStatus() {
        return Stream.of(Arguments.of(TransactionStatusEnum.ERRORED.getName(), true),
                         Arguments.of(TransactionStatusEnum.COMPLETED.getName(), false));
    }

    /**
     * Test method for
     * {@link com.tdameritrade.ctg.cashmovement.posting.PostingCommonUtils#checkTransactionErrored(java.lang.String)}.
     */
    @ParameterizedTest
    @MethodSource("dataSetForTransactionStatus")
    public void testCheckTransactionErrored(final String status, final boolean result) throws Exception {
        assertThat(PostingCommonUtils.checkTransactionErrored(status), is(equalTo(result)));
    }
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.tdameritrade.ctg</groupId>
        <artifactId>cashmovement-parent</artifactId>
        <version>1-SNAPSHOT</version>
        <relativePath>../cashmovement-parent</relativePath>
    </parent>

    <name>CTG Cash Movement Server</name>
    <groupId>com.tdameritrade.ctg</groupId>
    <artifactId>cashmovement-server</artifactId>
    <packaging>war</packaging>

    <dependencies>
...
        <dependency>
            <artifactId>junit-addons</artifactId>
            <groupId>junit-addons</groupId>
            <version>${junit-addons.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xmlParserAPIs</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xercesImpl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-runner</artifactId>
            <version>${junit.platform.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
...
        <plugins>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
                <configuration>
                    <forkCount>${surefire.fork.count}</forkCount>
                    <reuseForks>${surefire.fork.reuse}</reuseForks>
                    <groups>${maven.surefire.include.groups}</groups>
                    <excludedGroups>${maven.surefire.exclude.groups}</excludedGroups>
                    <properties>
                        <includeTags>junit5</includeTags>
                    </properties>                    
                </configuration>
...
            </plugin>
        </plugins>
    </build>
</project>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project cashmovement-common: No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project cashmovement-common: No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:579)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
mvn -Dtest=PostingCommonUtilsTest test