2

当我使用 ant 运行测试时,我无法说服一些新代码与我的 JUnit 测试很好地配合使用。

我有一些使用适用于 Java 的 AWS 开发工具包与 AWS(亚马逊网络服务)交互的代码。当我的 Junit 测试遇到引用此 SDK 中任何内容的代码时,测试会失败。当我逐步完成时,代码本身运行良好,失败的是预先存在的和其他成功的 Junit 测试。

我已经使用 -v 选项从命令行运行了 ant,我可以看到 AWS SDK for Java 的 jar 文件包含在类路径中。Ant 和 JUnit 也在那里。-v 选项显示在 actOnTestResult 中报告了失败,但这不是错误本身发生的地方。

ant -v 的完整输出为:

Apache Ant(TM) version 1.8.2 compiled on December 3 2011
Trying the default build file: build.xml
Buildfile: /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/build.xml
Detected Java version: 1.6 in: /usr/lib/jvm/jdk1.6.0_32/jre

Detected OS: Linux

parsing buildfile /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/build.xml with URI = file:/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/build.xml

Project base dir set to: /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy

parsing buildfile jar:file:/usr/share/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/usr/share/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file

Importing file /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/lib/one-jar-ant-task.xml from /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/build.xml

Overriding previous definition of reference to ant.projectHelper

parsing buildfile /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/lib/one-jar-ant-task.xml with URI = file:/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/lib/one-jar-ant-task.xml

Override ignored for property "one-jar.dist.dir"

Overriding previous definition of reference to ant.projectHelper

Build sequence for target(s) `junit' is [init, compile, junit]

Complete build sequence is [init, compile, junit, input-cmdlineargs, jar, onejar, run-cmdline, input-fileprops, run-hudson, help, clean, usage, input-eclipseargs, run-eclipse, ]


init:

 [echo] Creating build directories...

[mkdir] Skipping /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/build because it already exists.

[mkdir] Skipping /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/build/class because it already exists.

[mkdir] Skipping /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/build/jar because it already exists.

[mkdir] Skipping /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/dist because it already exists.


compile:

 [echo] Compiling source files...

[javac] /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/src/AwsCredentials.properties skipped - don't know how to handle it

[javac] com/sportingindex/tradingservices/hadoop/aws/S3DataExtractionDeploy.java omitted as /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/build/class/com/sportingindex/tradingservices/hadoop/aws/S3DataExtractionDeploy.class is up to date.

[javac] com/sportingindex/tradingservices/test/hadoop/aws/JUnit_S3DataExtractionDeploy.java omitted as /home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/build/class/com/sportingindex/tradingservices/test/hadoop/aws/JUnit_S3DataExtractionDeploy.class is up to date.


junit:

[junit] Implicitly adding /usr/share/ant/lib/junit.jar:/usr/share/java/ant-launcher-1.8.2.jar:/usr/share/ant/lib/ant.jar:/usr/share/ant/lib/ant-junit.jar:/usr/share/ant/lib/ant-junit4.jar to CLASSPATH

[junit] Executing '/usr/lib/jvm/jdk1.6.0_32/jre/bin/java' with arguments:

[junit] '-classpath'

[junit] '/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/build/class:/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/lib/aws-java-sdk-1.3.7.jar:/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/lib/commons-codec-1.6.jar:/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/lib/commons-collections-3.2.1.jar:/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/lib/commons-logging-1.0.4.jar:/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/lib/httpclient-4.1.3.jar:/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/lib/httpcore-4.2.jar:/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/lib/junit.jar:/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/lib/one-jar-ant-task-0.97.jar:/usr/share/ant/lib/junit.jar:/usr/share/java/ant-launcher-1.8.2.jar:/usr/share/ant/lib/ant.jar:/usr/share/ant/lib/ant-junit.jar:/usr/share/ant/lib/ant-junit4.jar'

[junit] 'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'

[junit] 'com.sportingindex.tradingservices.test.hadoop.aws.JUnit_S3DataExtractionDeploy'

[junit] 'filtertrace=true'

[junit] 'haltOnError=false'

[junit] 'haltOnFailure=true'

[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'

[junit] 'showoutput=false'

[junit] 'outputtoformatters=true'

[junit] 'logfailedtests=true'

[junit] 'logtestlistenerevents=false'

[junit] 'crashfile=/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/junitvmwatcher8947588636768864827.properties'

[junit] 'propsfile=/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/junit7746049445603740673.properties'

[junit]

[junit] The ' characters around the executable and arguments are

[junit] not part of the command.

[junit] Running com.sportingindex.tradingservices.test.hadoop.aws.JUnit_S3DataExtractionDeploy

[junit] Tests run: 4, Failures: 0, Errors: 4, Time elapsed: 0.756 sec


BUILD FAILED

/home/tonyb1/Dev/Workspace/S3DataExtractionDeploy/build.xml:218: Test com.sportingindex.tradingservices.test.hadoop.aws.JUnit_S3DataExtractionDeploy failed

at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.actOnTestResult(JUnitTask.java:1954)

at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:854)

at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1899)

at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:800)

at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)

at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)

at org.apache.tools.ant.Task.perform(Task.java:348)

at org.apache.tools.ant.Target.execute(Target.java:390)

at org.apache.tools.ant.Target.performTasks(Target.java:411)

at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)

at org.apache.tools.ant.Project.executeTarget(Project.java:1368)

at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)

at org.apache.tools.ant.Project.executeTargets(Project.java:1251)

at org.apache.tools.ant.Main.runBuild(Main.java:809)

at org.apache.tools.ant.Main.startAnt(Main.java:217)

at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)

at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)


Total time: 2 seconds

如果我通过 Eclipse 运行或调试测试,那很好。只有在使用 ant 运行测试时才会出现错误。

4

2 回答 2

0

我和你有同样的问题。我发现我需要再添加一个 jar(不仅是 junit.jar):hamcrest-core.jar 到类路径中。

更多:http: //junit.org/dependencies.html

于 2015-04-01T02:53:58.133 回答
-1

您必须比较 ant 和 eclipse 之间的类路径。就我而言,我的 ant 类路径中有 ant jar,所以如果您使用 includeruntime=true,我需要排除 ant 文件中的 ant。和其他的,你还应该检查你的 junit 运行时类路径中的测试类和类路径。

于 2017-12-14T02:45:38.837 回答