javajunitversion-compatibility

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


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


Solution

  • 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>