我无法让JUnit处理简单的Java示例

时间:2012-09-18 00:40:23

标签: java maven junit

我无法让这个JUnit测试工作在我正在研究的这个简单的Java示例上。它可以在Eclipse中运行,但不能从命令行运行... mvn test

这是我的测试代码:

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

1 个答案:

答案 0 :(得分:3)

您需要将maven-compiler-plugin配置为使用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>