我能';无法让JUnit在easy Java示例上工作
我无法让这个JUnit测试在我正在处理的这个简单Java示例上运行。它在Eclipse内部工作,但不从命令行工作。。。mvn测试 以下是我的测试代码:我能';无法让JUnit在easy Java示例上工作,java,maven,junit,Java,Maven,Junit,我无法让这个JUnit测试在我正在处理的这个简单Java示例上运行。它在Eclipse内部工作,但不从命令行工作。。。mvn测试 以下是我的测试代码: import junit.framework.Assert; import org.junit.Test; import org.runnablejar.TestJAR.App; public class TestApp { @Test public void testPrintHelloWorld() {
import junit.framework.Assert;
import org.junit.Test;
import org.runnablejar.TestJAR.App;
public class TestApp {
@Test
public void testPrintHelloWorld() {
Assert.assertEquals(App.getHelloWorld(), "Hello Worl");
}
}
以下是我的测试输出:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building TestJAR
[INFO] task-segment: [test]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/jsmith/workspace-sts-3.0.0.RELEASE/TestJAR/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/jsmith/workspace-sts-3.0.0.RELEASE/TestJAR/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 2 source files to /home/jsmith/workspace-sts-3.0.0.RELEASE/TestJAR/target/test-classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
/home/jsmith/workspace-sts-3.0.0.RELEASE/TestJAR/src/test/java/TestApp.java:[7,2] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
@Test
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Mon Sep 17 20:36:52 EDT 2012
[INFO] Final Memory: 10M/98M
[INFO] ------------------------------------------------------------------------
您需要将
maven编译器插件配置为使用1.5或1.6
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
org.apache.maven.plugins
maven编译器插件
1.6
1.6