@Test注释不起作用junit 4

发布于 2024-11-27 02:45:03 字数 630 浏览 6 评论 0原文

我正在尝试在 Maven 项目中使用 Jnuit 4 测试一个类。当我从 STS 运行测试时,测试运行成功,但是当我尝试从 Maven 命令行运行它时,出现以下错误: -source 1.3 不支持注释 (使用-source 5或更高版本来启用注释) @Before

测试中的代码是:

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..."); 
    }
}

我正在使用 Junit 4.8.1 作为 maven 依赖项

我已检查我的合规级别是 1.6 并且我正在使用 jdk 1.6

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青丝拂面 2024-12-04 02:45:03

您需要在 pom.xmlbuild 部分添加 maven-compiler-plugin 配置

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

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>
你的笑 2024-12-04 02:45:03

您是否为您的 maven-compiler-plugin 设置了适当的 sourcetarget 根据文档

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文