gpt4 book ai didi

android - java.lang.RuntimeException : Stub! 在Android 项目中运行Junit

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:44:44 26 4
gpt4 key购买 nike

在一个 android 项目中,我尝试运行简单的 junit 测试。他们总是失败:

java.lang.RuntimeException: Stub!
at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:5)
at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:7)
at com.my.android.JsonParser.getJSONFromUrl(JsonParser.java:27)
at com.my.android.test.JsonParser_Test.getJson(JsonParser_Test.java:19)

这是它失败的行,任何新的类启动都会这样做。

 public JSONObject getJSONFromUrl(String url) {
DefaultHttpClient httpClient = new DefaultHttpClient();
...
}

在几篇文章中,我发现 junit jar 应该包含在 Android SDK 之前。我在 IntelliJ 中做到了这一点,但我没有帮助。我正在使用 junit 4.9Android SDK 4.2.2

最佳答案

我认为 robolectric 对您很有用。

Running tests on an Android emulator or device is slow! Building, deploying, and launching the app often takes a minute or more. That’s no way to do TDD. There must be a better way.

Wouldn’t it be nice to run your Android tests directly from inside your IDE? Perhaps you’ve tried, and been thwarted by the dreaded 'java.lang.RuntimeException: Stub!'?

http://pivotal.github.com/robolectric/

关于android - java.lang.RuntimeException : Stub! 在Android 项目中运行Junit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15828782/

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