无法从Maven项目执行testng文件.Maven Surefire插件的例外



我创建了用于测试我的Web应用程序之一的Maven项目。我想根据几个参数执行我的项目。因此,我在pom.xml中添加了几个参数,并将这些属性传递给了我的插件。

在执行Maven项目期间,我过去两天的错误低于错误 [错误]无法执行目标org.apache.maven.plugins:maven-surefire-plugin:2.20:项目理智上的测试(默认测试):未执行测试!(set -dfailifnotests = false忽略此错误。) -> [help 1]

i什至将较早的堆栈上的流链链路转介到解决此错误。[无法执行目标org.apache.maven.plugins:maven-surefire-plugin:2.12:test(default-test(默认测试))。

但是,这些解决方案没有帮助我解决这个问题。我尝试了建议的大多数解决方案

1) Tried cleaning project
2) updated my maven project and dependencies. 
3) Ran in debug mode also
4) Recreated my maven project also

请分享您解决此问题的建议

另外,我正在从build tag remvoing dependecy插件,测试ng文件,用于调用的java文件中发布我的pom.xml文件。

     - POM.XML

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- This configuration need to be modified for the environment to be run and type of test to be executed -->
        <test>Web</test>
        <!-- Sanity, Regression -->
        <testtype>Sanity</testtype>
        <sanitysuiteFile>Sanity.xml</sanitysuiteFile>
        <regressionsuiteFile>Regression.xml</regressionsuiteFile>
    </properties>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20</version>
        <configuration>
            <suiteXmlFiles>
                <suiteXmlFile>${sanitysuiteFile}</suiteXmlFile>
            </suiteXmlFiles>
        </configuration>
    </plugin>
</plugins>
</build>
</project>
     - TestNg.XML
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="Suite">
      <test name="Test">
       <parameter name="selenium.env" value="UAT" />
      <parameter name="selenium.browser" value="IE" />
      <parameter name="selenium.pbrowser" value="Mozilla" /> 
        <classes>
          <class name="test.SanityTest"/>
        </classes>
      </test> <!-- Test -->
    </suite> <!-- Suite -->

以下错误在调试模式下运行该项目时收到的错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20:test (default-test) on project Sanity: 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.20:test (default-test) on project Sanity: No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    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:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    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.SurefireHelper.reportExecution(SurefireHelper.java:86)
    at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary(SurefirePlugin.java:334)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:937)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:785)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    ... 20 more
[ERROR] 

尝试构建项目时是否会遇到错误?如果是,则在您的pom.xml中添加以下插件,我将忽略测试用例并构建您的项目。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
            <testFailureIgnore>true</testFailureIgnore>
        </configuration>
</plugin>   

我能够解决问题。实际上,问题在于我的pom.xml我在属性标签中定义了我的xml文件,并将输入传递给了我的SureFire插件。现在我的pom.xml看起来像

属性:

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <environment></environment>
  <browser></browser>
</properties>

surefireplugin:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.20</version>
  <inherited>true</inherited>
  <configuration>
    <suiteXmlFiles>
      <!-- Modify this parameter value based on the testtype -->
      <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
    </suiteXmlFiles>
    <systemPropertyVariables>
      <browserName>${environment}</browserName>
      <testRunID>${browser}</testRunID> 
    </systemPropertyVariables>
  </configuration>
</plugin>

现在,我的输入来自maven命令行,如

mvn -X clean test Denvironment=UAT Dbrowser=IE -Dsurefire.suiteXmlFiles=sanity.xml

使用command system.getProperty("浏览器")

在我的Java文件中检索这些值

最新更新