gpt4 book ai didi

java - jUnit 测试在 Eclipse 中工作,但在 ant 中失败 - java.lang.RuntimeException : Stub

转载 作者:搜寻专家 更新时间:2023-10-31 20:28:54 25 4
gpt4 key购买 nike

我的项目有单元测试。它们在 Eclipse 中运行良好,但在 ant 中失败并出现错误:

java.lang.RuntimeException: Stub!

我已经根据 this 从 EclipseIDE 自动生成了我的 ant build.xml文章。

我的 build.xml 文件:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="main" name="MyProjectJavaTest">
<property environment="env"/>
<property name="junit.output.dir" value="junit"/>
<property name="MyProject.location" value="../MyProject"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>

<path id="JUnit 4.libraryclasspath">
<pathelement location="../../../../../winapl/adt-bundle-windows-x86/eclipse/plugins/org.junit_4.8.2.v4_8_2_v20110321-1705/junit.jar"/>
<pathelement location="../../../../../winapl/adt-bundle-windows-x86/eclipse/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar"/>
</path>

<path id="Android 4.2.libraryclasspath">
<pathelement location="../../../../../winapl/adt-bundle-windows-x86/sdk/platforms/android-4.2/android.jar"/>
</path>

<path id="Android Dependencies.libraryclasspath"/>
<path id="Persisted container [com.android.ide.eclipse.adt.DEPENDENCIES for project [MyProject]].libraryclasspath"/>
<path id="MyProject.classpath">
<pathelement location="${MyProject.location}/bin/classes"/>
<path refid="Android 4.2.libraryclasspath"/>
<path refid="Android Dependencies.libraryclasspath"/>
<path refid="Persisted container [com.android.ide.eclipse.adt.DEPENDENCIES for project [MyProject]].libraryclasspath"/>
</path>

<path id="MyProjectJavaTest.classpath">
<pathelement location="bin"/>
<path refid="JUnit 4.libraryclasspath"/>
<path refid="MyProject.classpath"/>
<pathelement location="lib/java-json.jar"/>
<pathelement location="lib/httpcomponents/commons-codec-1.6.jar"/>
<pathelement location="lib/httpcomponents/commons-logging-1.1.1.jar"/>
<pathelement location="lib/httpcomponents/fluent-hc-4.2.5.jar"/>
<pathelement location="lib/httpcomponents/httpclient-4.2.5.jar"/>
<pathelement location="lib/httpcomponents/httpclient-cache-4.2.5.jar"/>
<pathelement location="lib/httpcomponents/httpcore-4.2.4.jar"/>
<pathelement location="lib/httpcomponents/httpmime-4.2.5.jar"/>
</path>

<target name="main" depends="MyProjectJavaTest,junitreport"/>

<target name="MyProjectJavaTest">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="my.android.MyProject.api.F1U8GetTermsAndConditions" todir="${junit.output.dir}"/>
<test name="my.android.MyProject.api.JsonMarshallerTest" todir="${junit.output.dir}"/>
<test name="my.android.MyProject.api.ParamsTest" todir="${junit.output.dir}"/>
<test name="my.android.MyProject.api.TP1GetServiceDescriptionTest" todir="${junit.output.dir}"/>
<test name="my.android.MyProject.api.TP2GetServiceDescriptionLogoTest" todir="${junit.output.dir}"/>
<test name="my.android.MyProject.api.TP3GetServiceListTest" todir="${junit.output.dir}"/>
<test name="my.android.MyProject.api.TP4GetServiceLogoTest" todir="${junit.output.dir}"/>
<test name="my.android.MyProject.api.TP5GetSubscribedServiceInformationTest" todir="${junit.output.dir}"/>
<test name="my.android.MyProject.api.TP6GetSubscribedServiceListTest" todir="${junit.output.dir}"/>
<test name="my.android.MyProject.api.TP7SendServiceNotificationTest" todir="${junit.output.dir}"/>
<test name="my.android.MyProject.api.TP8SubscribeToServiceTest" todir="${junit.output.dir}"/>
<test name="my.android.MyProject.api.WMClientImplAndHMEIntegrationTest" todir="${junit.output.dir}"/>
<test name="my.android.MyProject.api.WMClientImplTest" todir="${junit.output.dir}"/>
<classpath refid="MyProjectJavaTest.classpath"/>
</junit>
</target>

<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
</target>
</project>

Ant 版本:1.9.2

junit 版本:4.8.2

Android 开发者工具版本:v21.0.0-531062

更新:我有以下错误:

java.lang.RuntimeException: Stub!
at org.apache.http.params.AbstractHttpParams.<init>(AbstractHttpParams.java:5)
at org.apache.http.params.BasicHttpParams.<init>(BasicHttpParams.java:6)
at my.android.myprojectlib.api.HttpClientProxyImpl.<init>(HttpClientProxyImpl.java:27)
at my.android.myprojectlib.api.HttpMethodExecutorImpl.<init>(HttpMethodExecutorImpl.java:28)
at my.android.myprojectlib.api.HttpMethodExecutorFactory.getHttpMethodExecutor(HttpMethodExecutorFactory.java:21)
at my.android.myprojectlib.api.WMClientImpl.<init>(WMClientImpl.java:66)
at my.android.myprojectlib.api.AbstractWMLibTest.setUp(AbstractWMLibTest.java:31)

UPD2:运行时类路径和构建类路径相同。

    <?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/java-json.jar"/>
<classpathentry kind="lib" path="lib/httpcomponents/commons-codec-1.6.jar">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/MyProjectLibJavaTest/lib/httpcomponents/javadoc.zip!/javadoc"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/httpcomponents/commons-logging-1.1.1.jar">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/MyProjectLibJavaTest/lib/httpcomponents/javadoc.zip!/javadoc"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/httpcomponents/fluent-hc-4.2.5.jar">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/MyProjectLibJavaTest/lib/httpcomponents/javadoc.zip!/javadoc"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/httpcomponents/httpclient-4.2.5.jar">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/MyProjectLibJavaTest/lib/httpcomponents/javadoc.zip!/javadoc"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/httpcomponents/httpclient-cache-4.2.5.jar">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/MyProjectLibJavaTest/lib/httpcomponents/javadoc.zip!/javadoc"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/httpcomponents/httpcore-4.2.4.jar">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/MyProjectLibJavaTest/lib/httpcomponents/javadoc.zip!/javadoc"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/httpcomponents/httpmime-4.2.5.jar">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/MyProjectLibJavaTest/lib/httpcomponents/javadoc.zip!/javadoc"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/MyProjectLib"/>
<classpathentry kind="output" path="bin"/>
</classpath>

最佳答案

当在类路径中的junit.jar 之前引用android.jar 时会出现问题。

在您的 build.xml 中,顺序似乎是正确的,但您指定的 id 中有一个空格:

<path id="JUnit 4.libraryclasspath">

您应该使用不带空格或其他特殊字符的 ID(不过,.-_ 没问题)。

您的 UPD1 中的堆栈跟踪显示没有 junit,这是缺少库的另一个迹象。

关于java - jUnit 测试在 Eclipse 中工作,但在 ant 中失败 - java.lang.RuntimeException : Stub,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18230115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com