0

I am trying to run a test using Maven by providing the testng.xml file. It is not running any test, although the build is successful.

POM.xml

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

    <groupId>com.sawanttech</groupId>
    <artifactId>LearningSelenium</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>LearningSelenium</name>
    <url>https://learningselenium.com</url>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.testSource>1.8</maven.compiler.testSource>
        <maven.compiler.testTarget>1.8</maven.compiler.testTarget>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.0.0-alpha-6</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.3.0</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>Regression</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.8.1</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M5</version>
                        <configuration>
                            <suiteXmlFiles>
                                <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                            </suiteXmlFiles>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite" verbose="3">
  <test name="Test1">
    <classes>
      <class name="testing.TestAB"/>
    </classes>
  </test>
</suite>

TestAB.java

package testing;

import org.testng.annotations.Test;

public class TestAB
{
    @Test
    public void ab()
    {
        System.out.println("ab test method called");
    }
    
}

Output:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.885 s
[INFO] Finished at: 2020-10-12T20:03:20+05:30
[INFO] ------------------------------------------------------------------------

Please help.

Edit: Added console message after fix was provided by Tibor Digana to fail the build and state the actual message for tests not being run:

D:\Java Testing\Selenium Automation\LearningSelenium>mvn test
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.sawanttech:LearningSelenium >-------------------
[INFO] Building LearningSelenium 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ Learning
Selenium ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ LearningSelen
ium ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @
LearningSelenium ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 31 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ Learn
ingSelenium ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ LearningSelenium
 ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[ERROR] Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[ERROR] Suite file D:\Java Testing\Selenium Automation\LearningSelenium\src\test
\resources\testng.xml is not a valid file
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.164 s
[INFO] Finished at: 2021-02-08T21:58:12+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.
0.0-M5:test (default-test) on project LearningSelenium: There are test failures.

[ERROR]
[ERROR] Please refer to D:\Java Testing\Selenium Automation\LearningSelenium\tar
get\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].
dump and [date].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] Suite file D:\Java Testing\Selenium Automation\LearningSelenium\src\test
\resources\testng.xml is not a valid file
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was
an error in the forked process
[ERROR] Suite file D:\Java Testing\Selenium Automation\LearningSelenium\src\test
\resources\testng.xml is not a valid file
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.for
k(ForkStarter.java:733)
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run
(ForkStarter.java:305)
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run
(ForkStarter.java:265)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute
Provider(AbstractSurefireMojo.java:1314)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute
AfterPreconditionsChecked(AbstractSurefireMojo.java:1159)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute
(AbstractSurefireMojo.java:932)
[ERROR]         at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo
(DefaultBuildPluginManager.java:137)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(Mojo
Executor.java:210)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(Mojo
Executor.java:156)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(Mojo
Executor.java:148)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.bu
ildProject(LifecycleModuleBuilder.java:117)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.bu
ildProject(LifecycleModuleBuilder.java:81)
[ERROR]         at org.apache.maven.lifecycle.internal.builder.singlethreaded.Si
ngleThreadedBuilder.build(SingleThreadedBuilder.java:56)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(
LifecycleStarter.java:128)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305
)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192
)
[ERROR]         at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
[ERROR]         at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
[ERROR]         at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
[ERROR]         at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
[ERROR]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:62)
[ERROR]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:43)
[ERROR]         at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhan
ced(Launcher.java:282)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Laun
cher.java:225)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExi
tCode(Launcher.java:406)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launch
er.java:347)
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
xception
4
  • Hi. Are you using this command to run test : mvn clean install test Oct 13, 2020 at 8:48
  • Yes. I am running mvn clean install test. Oct 13, 2020 at 13:33
  • I am having same issue, but reading through the comments i am not getting in which file need to to put changes to print the error? Can you please help me here Note: I was not able to comment to original thread because of having low reputation for comments.
    – Sushil.R
    Feb 21, 2022 at 15:31
  • You will get this error when your testng.xml file is not in the project root directory and you have passed <suiteXmlFile>testng.xml</suiteXmlFile> which means it will look for the testng.xml file in the project root directory. Feb 24, 2022 at 1:30

1 Answer 1

1

According to the Surefire configuration, I guess the file src/test/resources/testng.xml does not exist. Pls post the project on GitHub. It's hard to investigate like this.

I believe this issue is similar to stackoverflow.

11
  • This issue is resolved by placing the testng.xml file at the root directory of the project instead of src/test/resources and using <suiteXmlFile>testng.xml</suiteXmlFile> in POM file. Feb 6, 2021 at 19:48
  • 1
    Hi Sandesh, I am the Apache developer and I want to provide a fix. or more information pls see the JIRA issue issues.apache.org/jira/browse/SUREFIRE-1885
    – tibor17
    Feb 6, 2021 at 23:00
  • It would be good if it is fixed by stating the actual reason for tests not being run. Please let me know what information you want. Feb 8, 2021 at 15:56
  • The test do not run because the XML file is not found (wrong place). Imagine your project apperas in /home/sandesh and the XML file appears in /home/sandesh/src/test/resources/testng.xml and then the config must be <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>. Similarily we can print such a hint in the error but the sanity check must crash in the plugin and then the user has to understand the error and shift the XML file to the right place.
    – tibor17
    Feb 8, 2021 at 16:18
  • Do you want me to run this testcase ? Feb 8, 2021 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.