Blaine Mucklow
Blaine Mucklow

Reputation: 591

Intellij/Maven Unit Test running issues

So I have issues running all the tests in my Maven project with Intellij. The reason for this is because a handful of modules are dependant on Native methods in a loaded dll. Since this dll can not be loaded more than once, I had to add a clause in my maven pom file that those tests would run in forked mode.

However, in Intellij I can not figure out how to make those same tests run as forked mode. I'd like to utilize the Intellij pretty UI for Unit tests with the green bar, and nice UT interfaces, however I can not run all tests in my project because of this issue.

Has anyone ever run into issues with Maven, Intellij and Unit tests and any tips on how to make them play nicely together?

Here is a snippet of my pom.xml file:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skip>true</skip>
            </configuration>
            <executions>
                <execution>
                    <id>allTests</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                        <excludes>
                            <exclude>**/pkgA/**/*Test.java</exclude>
                        </excludes>
                    </configuration>
                </execution>
                <execution>
                    <id>forkedTests</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                        <forkMode>pertest</forkMode>
                        <includes>
                            <include>**/pkgA/**/*Test.java</include>
                        </includes>
                        <excludes>
                            <exclude>**/SpecificTest.java</exclude>
                            <exclude>**/*PerformanceTest.java</exclude>
                        </excludes>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Upvotes: 4

Views: 2857

Answers (3)

PaoloC
PaoloC

Reputation: 4125

In IntelliJ 14, you have Fork mode option in the Run Configuration dialog. When you're running all tests in a class/suite, you can enable forkMode=method that should be equivalent to your maven's pertest.

Upvotes: 0

Pascal Thivent
Pascal Thivent

Reputation: 570615

However, in Intellij I can not figure out how to make those same tests run as forked mode.

I don't think IntelliJ allows to tweak the behavior of its test runner.

Has anyone ever run into issues with Maven, Intellij and Unit tests and any tips on how to make them play nicely together?

Some ideas/suggestions:

  • use Maven to run all the tests, even under IntelliJ ~or~
  • use a TestSuite that does the DLL initialization and references all the TestCases, which of course no longer load the DLL.

Upvotes: 0

CrazyCoder
CrazyCoder

Reputation: 402543

Please vote for the feature request: Allow unit tests to be run seperate JVMs in IntelliJ IDEA issue tracker.

Upvotes: 2

Related Questions