我已经创建了Maven项目来测试我的一个Web应用程序。我想基于几个参数执行我的项目。所以我在POM.XML中添加了一些参数,并将这些属性作为输入传递给我的插件。
在执行我的maven项目期间,我在过去两天内遇到错误 [错误]无法执行目标org.apache.maven.plugins:maven-surefire-plugin:2.20:test(default-test)on project Sanity:没有执行任何测试! (设置-DfailIfNoTests = false以忽略此错误。) - > [帮助1]
我甚至引用了早期的堆栈流量链接来解决此错误。[Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.
但是没有一个解决方案帮助我解决了这个问题。我尝试了大多数建议的解决方案
1) Tried cleaning project
2) updated my maven project and dependencies.
3) Ran in debug mode also
4) Recreated my maven project also
请分享您的建议以解决此问题
另外,我发布了我的POM.XML文件,来自Build标签remvoing dependecy插件,Test Ng文件,用于调用的Java文件
- 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]
答案 0 :(得分:0)
您在尝试构建项目时是否收到错误? 如果是,则在pom.xml中添加以下插件,我将忽略测试用例并构建项目。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
答案 1 :(得分:0)
我能够解决这个问题。实际上,问题在于我的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
使用命令System.getProperty(&#34; browser&#34;)
在我的java文件中检索这些值