我正在尝试针对使用Ant运行的Android应用程序进行JUnit测试。在使用Eclipse时,这没问题,所有内容都可以编译并且可以毫无问题地运行。
目前,我收到org.junit.Test的ClassNotFoundException。
我正在运行以下命令
ant clean debug - success
ant uninstall - success
ant installt - success
ant test - failure
错误日志:
test:
[echo] Running tests ...
[exec] INSTRUMENTATION_RESULT: shortMsg=java.lang.ClassNotFoundException
[exec] INSTRUMENTATION_RESULT: longMsg=java.lang.ClassNotFoundException: org.junit.Test
[exec] INSTRUMENTATION_CODE: 0
我想,它错过了junit.jar文件。我将其添加到了ANT_HOME / lib目录中,但没有任何效果。ant-junit.jar库已经在“ ANT_HOME / lib”中,我不需要复制它。
我还尝试将其添加到测试项目的类路径中,并将其标记为要导出。同样在那种情况下,结果保持不变。
我还让eclipse生成一个build.xml并将其与android update project生成的文件合并。没什么区别,我收到同样的错误。
我确定我在这里很容易错过一些事情。如果需要进一步的配置详细信息,我将很乐意提供它们。我感谢您的帮助。
build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="FSTest" default="help">
<property file="local.properties" />
<property file="ant.properties" />
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<loadproperties srcFile="project.properties" />
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<import file="custom_rules.xml" optional="true" />
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>
ant.properties:
tested.project.dir=../FS
external.libs.dir=libs
project.properties:
target=android-11
问题出在我的build.xml文件中。我根据此处给出的示例对其进行了修改:http : //www.vogella.com/articles/ApacheAnt/article.html,此后它起作用了。
这些行是与众不同的:
<path id="junit.class.path">
<pathelement location="libs/junit.jar" />
<pathelement location="${build.dir}" />
</path>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句