开发者

@Test annotation not working junit 4

I'am trying to test a class with Jnuit 4 in a maven project. The test runs successfully when I run it from my STS, but when I try to run it from maven command line, I get the following error: annotations are开发者_开发技巧 not supported in -source 1.3 (use -source 5 or higher to enable annotations) @Before

Code under test is:

public class MyContollerTest{
 @Before
 public void setup(){
    System.out.println("This is MyControllerTest before..."); 
 }
    @Test
    public void testShouldTest(){
        System.out.println("This is MyControllerTest"); 
    }
    @After
    public void tearDown(){
        System.out.println("This is MyControllerTest after..."); 
    }
}

I'm using the Junit 4.8.1 as maven dependecy

I have checked my complience level is 1.6 and I'm using jdk 1.6


You'll need to add maven-compiler-plugin config in the build section of the pom.xml

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <verbose>true</verbose>
        <compilerVersion>1.6</compilerVersion>
        <source>1.6</source>
        <target>1.6</target>
      </configuration>
    </plugin>
  </plugins>
</build>


Did you set appropriate source and target of your maven-compiler-plugin according to the documentation?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜