2
votes

comment réparer l'erreur du plugin maven surefire [il y avait une erreur dans le processus forké]?

J'essaye d'exécuter mon exemple de projet qui utilise Maven-testNG-cucumber et de le déployer en utilisant docker. voici mon Dockerfile

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

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>

Le scénario ci-dessus fonctionne parfaitement lorsque j'exécute le projet localement en utilisant mvn verify .Ensuite, j'essaye de créer l'image à l'aide de docker build -t sample. . cette fois, j'ai l'erreur suivante.

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

Toute aide serait très appréciée


0 commentaires

3 Réponses :


0
votes

Le journal des exceptions ci-dessus indique clairement qu'il est impossible de trouver la classe TestRunner. Assurez-vous que votre classe TestRunner est sur le chemin de classe.

J'obtenais une exception similaire car il y avait quelques caractères supplémentaires ajoutés dans la section Classes du fichier XML TestNG. Il vaut la peine de vérifier que le fichier XML TestNG est correct et ne contient pas de caractères supplémentaires par rapport à la structure nécessaire.


0 commentaires

0
votes

J'ai eu un problème similaire et après avoir utilisé une ancienne version de maven-surefire-plugin , j'ai résolu mon problème.

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


0 commentaires

0
votes

J'ai rencontré le même problème mais il a été résolu avec une solution différente, vous pouvez également vérifier les problèmes ci-dessous.

En fait, j'ai donné le mauvais chemin testNG.xml dans POM.XML, c'est pourquoi cela m'a renvoyé cette erreur. Veuillez vérifier votre chemin testNG.xml.


0 commentaires