4

Suppose I have a junit custom class loader, which reads the test data from a text file and create and run tests in runtime. The runner uses no test class.

Now I would like to run it with surefire maven plugin. That is, I would like to specify the runner as a parameter of the the surefire plugin "execution" in the pom.xml.

Can I do that?

Michael
  • 10,185
  • 12
  • 59
  • 110

3 Answers3

4

No. As far as I know, there is no way of specifying a Runner class in the maven-surefire-plugin. However, you should be able to create a single Test-Class and use the @RunWith(YourRunner.class) to let it run with your custom runner.

I think that is because the intended use case for Runners is on a per-test basis, not on a project-level. You can have a project with mixed uses of various Runners, e.g. some are Spring-based, some are concurrent, some run with JUnit3, some with JUnit4 etc.

mhaller
  • 14,122
  • 1
  • 42
  • 61
0

In my project i resolve same task with plugin exec-maven-plugin

I have custom Runner, which run junit test with special parameters. I execute my runner with maven command: mvn test -Dparam1=value1 -Dparam2=value2 -Dparam3=value3

In pom.xml:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.5.0</version>
            <executions>
                <execution>
                    <phase>test</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <classpathScope>test</classpathScope>
                        <mainClass>com.example.domain.MyMainClass</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
OnoDee
  • 1
0

Depending on what you want to achieve, you might be able to influence the test behavior globally by using a custom RunListener. Here is how to configure it with the Maven Surefire plugin: http://maven.apache.org/plugins/maven-surefire-plugin/examples/junit.html#Using_custom_listeners_and_reporters

(I posted the same response to a similar question, namely: Globally setting a JUnit runner instead of @RunWith)

Community
  • 1
  • 1
Madoc
  • 5,841
  • 4
  • 25
  • 38