Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Java Surefire Unable to create test class

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.

like image 586
Secret-guy Avatar asked Aug 13 '26 16:08

Secret-guy


1 Answers

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

like image 86
Simon Hill Avatar answered Aug 16 '26 16:08

Simon Hill