0

I have created Maven project for testing one of my web application. I wanted to execute my project based on few parameters. So I added few parameters to my POM.XML and passed those properties as input to my plugins.

During execution of my maven project, I am getting below error for last two days [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]

I even referred the earlier stack over flow link to resolve this error.[Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.

But none of the solutions helped me to resolve the issue. I tried most of the solutions suggested

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

Please share your suggestions to resolve this issue

Also, I am posting my POM.XML file from Build tag remvoing dependecy plugins, Test Ng file, Java file used for invoking

     - 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 -->

Below error received when ran the project in debug mode

[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] 
Kalamarico
  • 5,466
  • 22
  • 53
  • 70
Priya
  • 69
  • 4
  • 15
  • You have read `No tests were executed`? – khmarbaise Sep 15 '17 at 10:56
  • Yes I am getting this below error – Priya Sep 15 '17 at 11:02
  • Also read `Set -DfailIfNoTests=false to ignore this error.`? – khmarbaise Sep 15 '17 at 11:10
  • Yes when I run my project with this command [clean install -DfailIfNoTests=false] in eclipse, my build was successful. But my java page was not launched – Priya Sep 15 '17 at 11:13
  • [INFO] --- maven-surefire-plugin:2.20:test (default-test) @ Sanity --- [INFO] No tests to run. – Priya Sep 15 '17 at 11:14
  • I tried command -X clean test -DfailIfNoTests=false also. Still, my java file is not invoked – Priya Sep 15 '17 at 11:37
  • Have you located your test file into `src/test/java` ? Have you named your test like `*Test.java` ? – khmarbaise Sep 15 '17 at 11:51
  • My test file is in location src/test/SanityTest.java. Also, get this error when I run in debug mode[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.) – Priya Sep 15 '17 at 11:56
  • Please remove the configuration for suite file from maven-surefire-plugin and retry.. – khmarbaise Sep 15 '17 at 12:32
  • what is your jdk version? if you are using java 7 version then you need to change the version of surefire plugin – Ravi Potnuru Sep 15 '17 at 12:33
  • I am using JDK1.8 – Priya Sep 15 '17 at 12:40
  • @khmarbaise : I tried commenting configuration and suiteXML tags. Still same error – Priya Sep 15 '17 at 12:42

2 Answers2

0

are you getting error when you trying to build the project? if yes the add the following plugin in your pom.xml i will ignore the test cases and build your project.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
            <testFailureIgnore>true</testFailureIgnore>
        </configuration>
</plugin>   
Rahul Chavan
  • 43
  • 2
  • 9
0

I was able to resolve the issue. Actually, the problem was with my POM.XML I defined my XML files in properties tag and passing as input to my surefire plugin. Now my POM.XML looks like

Properties:

<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>

Now my input is given from maven command line like

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

These values are retrieved in my java file using command System.getProperty("browser")

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
Priya
  • 69
  • 4
  • 15