简体   繁体   English

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

[英]jUnit tests work in Eclipse, but fail in ant - java.lang.RuntimeException: Stub

I have unit tests for my project. 我为我的项目进行了单元测试。 They run fine in Eclipse but fail in ant with errors: 它们在Eclipse中运行良好但在ant中失败并出现错误:

java.lang.RuntimeException: Stub!

I've automaticaly generated my ant build.xml from EclipseIDE acording to this article. 我automaticaly产生从的eclipseIDE acording到我的蚂蚁的build.xml 文章。

My build.xml file: 我的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 version: 1.9.2 蚂蚁版:1.9.2

junit version: 4.8.2 junit版本:4.8.2

Android Developer Tools Build: v21.0.0-531062 Android开发者工具版:v21.0.0-531062

UPD: I have got following error: UPD:我有以下错误:

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: Runtime classpath and build classpath are the same. 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>

The problem occurs when the android.jar is referenced before the junit.jar in the classpath. 在类路径中的junit.jar之前引用android.jar时会发生此问题。

In your build.xml , the order seems correct, but you specified the id with a space in it: build.xml ,顺序似乎正确,但是您在其中指定了带有空格的id:

<path id="JUnit 4.libraryclasspath">

You should use ids without spaces or other special characters (.-_ are ok, though). 你应该使用没有空格或其他特殊字符的ids(.- _但是没问题)。

The stacktrace in your UPD1 shows no junit, which is another indication for a missing lib. UPD1中的堆栈跟踪显示没有junit,这是缺少lib的另一个指示。

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

相关问题 java.lang.RuntimeException:存根! 在Android中使用Mockito - java.lang.RuntimeException: Stub! in Android with Mockito 如何解决java.lang.RuntimeException:Stub! .java文件中的错误? - How to resolve java.lang.RuntimeException: Stub! error in .java file? java.lang.RuntimeException:无法启动活动ComponentInfo:Stub - java.lang.RuntimeException: Unable to start activity ComponentInfo: Stub Apache DefaultHttpClient 调用导致“java.lang.RuntimeException: Stub!” - Apache DefaultHttpClient invocation results in "java.lang.RuntimeException: Stub!" java.lang.RuntimeException:无法实例化 Android 存根 - java.lang.RuntimeException: Unable to instantiate Android stub 线程“main”中的异常 java.lang.RuntimeException: Stub XmlPullParserFactory - Exception in thread "main" java.lang.RuntimeException: Stub XmlPullParserFactory PeripherialManager.getInstance() 抛出 java.lang.RuntimeException:存根 - PeripherialManager.getInstance() throws java.lang.RuntimeException: Stub 线程“main”中的异常java.lang.RuntimeException:Stub - Exception in thread “main” java.lang.RuntimeException: Stub java.lang.RuntimeException:存根? - Android 代码覆盖率? - java.lang.RuntimeException: Stub! - Android Code Coverage? QRCodeReaderView java.lang.RuntimeException:无法连接到相机服务 - QRCodeReaderView java.lang.RuntimeException:Fail to connect to camera service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM