Maven Java Surefire Unable to create test class
Asked Answered
G

1

6

I encountered with the problem, when I ran mvn test. Here's a part of the output:

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] Unable to create test class 'com.models.ExampleTest'
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] Unable to create test class 'com.ExampleTest'
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:657)
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:283)
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:246)
[ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1161)
[ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1002)

and here's part of my pom.xml:

<build>
       <plugins>    
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                    <useSystemClassLoader>false</useSystemClassLoader>
                </configuration>
            </plugin>
        </plugins>
</build>
<dependencies>
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
</dependencies>

I've added <useSystemClassLoader>false</useSystemClassLoader> because I had problem when the mvn test command gave me Could not find or load main class org.apache.maven.surefire.booter.ForkedBooter. So I suppose there-s something with my ClassLoader. I use Ubuntu 18.04, openjdk-11 and maven 3.6.0. But I tried to run this with oracle-jdk-11 and openjdk-8. What's more, this problem doesn't depend on a project. I've created an empty project with maven and added there simple class and simple test - the result was the same.

Godwin answered 19/2, 2019 at 8:13 Comment(5)
I'd say it looks like there's a problem with the Java process maven tries to launch to run the tests. Have you looked to the dump files?Bibcock
Yes, similar information there - Unable to create test class, caused by ClassNotFounfExceptionGodwin
Are you using jacoco in your project?Derian
Yee, I tried. But when I removed it from my pom.xml nothing changed. Also, tried creating new clean project and the problem remained.Godwin
Same issue with openjdk 11.0.2 on macOS Mojave 10.14.4 (18E226). Same surefire version but junit v5.3.2.Meissner
N
1

As the log says :

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

You need to look into the xxx.dump file. You should find it in your project's target directory. In that file you will find the cause and stacktrace that caused the

[ERROR] Unable to create test class 'com.models.ExampleTest'

This stacktrace will be different from the one in your output and will help you identify the real cause of the error (in my case it was Javassist version but it is probably irrelevant in your situation).

From my understanding (I've no knowledge about Surefire), Surefire act as a container and create a process to run the tests. If something goes wrong in this "internal" process it will be logged in the dump file. But it is not Surefire's fault (as the output might let think).

Nea answered 28/1, 2021 at 10:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.