user1553680
user1553680

Reputation: 349

how to fix the maven surefire plugin error [there was error in the forked process]?

I am trying to run my sample project which uses Maven- testNG-cucumber and deploy it using docker . here is my Dockerfile

FROM    maven:3.6.0-jdk-8
RUN     mkdir /docker
WORKDIR /docker
COPY    pom.xml .
COPY    testng.xml .
COPY    src .
RUN     mvn clean verify 

POM.XML

    <dependencies>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm-deps</artifactId>
        <version>1.0.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>1.2.5</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.8</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.masterthought</groupId>
        <artifactId>cucumber-reporting</artifactId>
        <version>3.8.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.44.0</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20.1</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
                <useSystemClassLoader>false</useSystemClassLoader>
            </configuration>
        </plugin>
        <plugin>
            <groupId>net.masterthought</groupId>
            <artifactId>maven-cucumber-reporting</artifactId>
            <version>3.8.0</version>
            <executions>
                <execution>
                    <id>execution</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <projectName>Sample</projectName>
                        <outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
                        <cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
                        <buildNumber>1</buildNumber>
                        <parallelTesting>false</parallelTesting>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

above scenario works completely fine when i run the project locally using mvn verify .Then i try to build the image using docker build -t sample . . this time i have got the following error .

 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project Sample: There are test failures.
 [ERROR] Please refer to /docker/target/surefire-reports for the individual test results.

 [ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.

 [ERROR] There was an error in the forked process

 [ERROR] Cannot find class in classpath: TestRunner
 [ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process

 [ERROR] Cannot find class in classpath: TestRunner
 [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork
 (ForkStarter.java:673)
 [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork
 (ForkStarter.java:535)
 [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run 
 (ForkStarter.java:280)
 [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run
 (ForkStarter.java:245)
 [ERROR] at 
 org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider
 (AbstractSurefireMojo.java:1124)
 [ERROR]         at 
 org.apache.maven.plugin.surefire.AbstractSurefireMojo.
 executeAfterPreconditionsChecked(AbstractSurefireMojo.java:954)

Any help would be much appreciated

Upvotes: 4

Views: 60641

Answers (6)

Rahim Khan Abdul
Rahim Khan Abdul

Reputation: 119

I faced the same issue. It got resolved after I did a maven clean build and then ran the test.

mvn clean install

Upvotes: 1

selenium Gabby
selenium Gabby

Reputation: 1

To resolve this issues I included the log4j2 dependency in my pom.xml file.

<dependency>
        <groupId>io.basc.framework</groupId>
        <artifactId>log4j2</artifactId>
        <version>1.8.3</version>
        <scope>test</scope>
    </dependency>

Find link below. maven repository

Upvotes: -1

I had the same issue, I just used the clean command for maven.

clean -f pom.xml

If you are working in IntelliJ you can use maven plugin instead. On the right side click maven Tab -> plugins -> clean -> clean:clean

Upvotes: 4

Brijesh Yadav
Brijesh Yadav

Reputation: 71

I faced the same issue but it got resolved with different solution, you can check below problems as well.

Actually i have given the wrong testNG.xml path in POM.XML that's why it was throwing me that error. Please cross verify your testNG.xml path.

Upvotes: 2

Channa
Channa

Reputation: 3767

I had a similar issue and after using older version of maven-surefire-plugin solved my issue.

       <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <!-- latest version does not work well with JUnit5 -->
            <version>2.19.1</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>1.0.3</version>
                </dependency>
                <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                    <version>5.0.3</version>
                </dependency>
            </dependencies>
        </plugin>

Upvotes: 6

Abhi
Abhi

Reputation: 53

The above exception log clearly states that it is unable to find the TestRunner class. Make sure your TestRunner class is on the classpath.

I was getting a similar exception due to there were few extra characters added in the Classes section of the TestNG XML file. Its worth checking TestNG XML file is correct and doesn't contain any extra chars than needed structure.

Upvotes: 0

Related Questions