@Test注释不起作用junit 4
我正在尝试在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在
pom.xml
的build
部分添加maven-compiler-plugin
配置You'll need to add
maven-compiler-plugin
config in thebuild
section of thepom.xml
您是否为您的
maven-compiler-plugin
设置了适当的source
和target
根据文档?Did you set appropriate
source
andtarget
of yourmaven-compiler-plugin
according to the documentation?