How to write Junit with Java 1.7 while running base code with 1.6

2k Views Asked by At

I would like to use java 7 in my tests and java 6 for the code. How to achieve this?

2

There are 2 best solutions below

0
Petr Mensik On BEST ANSWER

You can also set source and target in the execution phase testCompile of the maven-compiler-plugin. So try something like this

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <executions>
       <execution>
           <id>testCompileWithJDK7</id>
           <phase>test-compile</phase>
           <configuration>
              <source>1.7</source>
              <target>1.7</target>              
           </configuration> 
       </execution>
    </executions>
</plugin>
2
René Link On

You can set the jvm that is used by the maven-surefire-plugin to point to the java 7 executable.

See http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#jvm