繁体   English   中英

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

[英]I can't get JUnit working on easy Java example

我无法让这个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] ------------------------------------------------------------------------

您需要将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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM