tintin
tintin

Reputation: 5867

@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

Upvotes: 1

Views: 5273

Answers (2)

Constantiner
Constantiner

Reputation: 14221

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

Upvotes: 1

Boris Pavlović
Boris Pavlović

Reputation: 64632

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>

Upvotes: 3

Related Questions