views:

1106

answers:

2

Right now I have both type of tests but when I say "mvn test" it only executes TestNG tests and not Junit. I want to execute both one after another. Any Idea ?

+2  A: 

There is an open issue for this, so there's no elegant way to do this.

It would be far simpler for you to pick a framework and stick with it.

Edit: My previous answer doesn't work because you can't specify dependencies in the execution. I've tried a few approaches, but the best I can manage is to create a profile for the TestNG dependency so you can toggle between TestNG and JUnit testing, there doesn't seem to be a means to run both TestNG and Junit 4 tests.

One other point to note: You can launch your JUnit tests from TestNG, but I think this only works for JUnit 3 tests.

Rich Seller
Of course this won't work because you can't add dependencies at the execution level. You could move the testng dependency into a profile to choose either junit or testng executions, but that's not what you're after. I'll have a look at the options and update if I find anything out
Rich Seller
Thanks rich, yeah thats true what you said in comments. I also tried to add property for "Junit" as "true" as described in that issue but doesn't helped me lot so decided to ask here. Thanks anyways :)
RN
Yes profiles is the solution.
RN
yeah but unfortunately not running for me please refere http://stackoverflow.com/questions/1238017/junit4-and-testng-in-one-project-with-maven
RN
A: 

I have a better solution.

The idea is to create two executions of the maven-surefire-plugin, one for JUnit, one for TestNG. You can disable one of TestNG or JUnit per execution by specifying nonexisting junitArtifactName or testNGArtifactName:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <executions>
        <execution>
            <phase>test</phase>
            <goals>
                <goal>test</goal>
            </goals>
            <configuration> 
                <testNGArtifactName>none:none</testNGArtifactName>
            </configuration>
        </execution>
        <execution>
            <id>test-testng</id>
            <phase>test</phase>
            <goals>
                <goal>test</goal>
            </goals>
            <configuration> 
                <junitArtifactName>none:none</junitArtifactName>
            </configuration>
        </execution>
    </executions>
</plugin>
lexicore