草庐IT

java - 线程 "main"java.lang.RuntimeException : Stub 中的异常

大家好,我遇到了这个奇怪的错误,我不知道为什么?packagecom.androidbook.services.httpget;importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;importorg.apache.http.HttpResponse;importorg.apache.http.client.HttpClient;importorg.apache.http.client.methods.HttpGet;importorg.apache.http.imp

android - 如何模拟/ stub Flutter 平台 channel /插件?

我阅读了introductiontoplatform-specificplugins/channels在Flutter网站上,我浏览了一些简单的插件示例,例如url_launcher://Copyright2017TheChromiumAuthors.Allrightsreserved.//UseofthissourcecodeisgovernedbyaBSD-stylelicensethatcanbe//foundintheLICENSEfile.import'dart:async';import'package:flutter/services.dart';const_channe

android - 如何模拟/ stub Flutter 平台 channel /插件?

我阅读了introductiontoplatform-specificplugins/channels在Flutter网站上,我浏览了一些简单的插件示例,例如url_launcher://Copyright2017TheChromiumAuthors.Allrightsreserved.//UseofthissourcecodeisgovernedbyaBSD-stylelicensethatcanbe//foundintheLICENSEfile.import'dart:async';import'package:flutter/services.dart';const_channe

android - 使用 Mockito Kotlin 模拟对象而不是 Stubbing 方法

我有以下代码:@RunWith(MockitoJUnitRunner::class)classOnboardingViewModelTest{@MocklateinitvarauthService:AuthServicelateinitvarinternetProvider:InternetStatusProviderprivatelateinitvarviewModel:OnboardingViewModel@Beforefunsetup(){internetProvider=mock()whenever(internetProvider.hasInternet()).thenRet

java - Apache DefaultHttpClient 调用结果为 "java.lang.RuntimeException: Stub!"

我正在涉足Android开发。我有一个将与RESTful资源交互的项目,我正在尝试弄清楚如何通过HTTP执行带有参数的基本GET。从我读到的所有内容来看,共识似乎是支持HTTPClient而不是HttpURLConnection。我编写了一个包装类,其中包含一个负责实例化关键对象以使用HTTPClient发出请求的方法:publicStringget(){StringresponseString=null;HttpClientclient=newDefaultHttpClient();HttpGetget=newHttpGet();try{get.setURI(newURI(this.

android - 在 Android Studio 上自动生成单元测试 stub

我正在为一些旧版android代码创建单元测试。目前我需要在test/java中为每个类/方法手动创建单元测试。是否有一种自动生成所有测试stub的方法?最好来自AndroidstudioIDE?(类似于parasoft如何为C++类和方法自动生成空测试stub)。我在Androidstudio1.2.1上使用robolectric 最佳答案 像这样:右击类名。转到->测试。选择函数,完成。 关于android-在AndroidStudio上自动生成单元测试stub,我们在StackOv

java - 安卓测试 : Stubbing out Retrofit with Mockito

在我的MainActivity中,我有一个名为getAPI的方法,它返回一个OTBServiceWrapper。这用于设置调用API的改造。在我的MainActivityTest文件中,我试图清除getApi方法正在进行的newOTBService().getService()调用所以我可以返回一个MockedOTBService,它将客户端更改为返回json的自定义客户端。如果我不得不在MockedOTBService中放置一个记录器,那么当前的实现将是MockedOTBService但也失败并调用真正的api,这是不想要的我想参加考试。我正在尝试使用MockitostubRetro

android - 获取 java.lang.RuntimeException : Stub when running Robolectric through Maven

好吧,我有一个奇怪的错误。当我通过IntelliJ运行测试时,它毫无问题地通过了。但是,如果我使用sure-fire插件或“mvncleantest”命令运行它,则会出现以下异常:shouldLoadMoreDataOnScrollBeyondTheThreshold(br.com.cybereagle.androidwidgets.listener.EndlessScrollListenerTest)Timeelapsed:2.73sec这是我的测试:@RunWith(RobolectricTestRunner.class)@Config(manifest=Config.NONE)p

android - 本地单元测试中 Build.VERSION.SDK_INT 的 stub 值

我想知道是否有办法stubBuild.Version.SDK_INT的值?假设我在ClassUnderTest中有以下几行:if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN){//dowork}else{//doanotherwork}如何覆盖所有代码?我的意思是我想使用不同的SDK_INT运行两个测试以进入两个block。是否可以在androidlocal单元测试中使用Mockito/PowerMockito?谢谢 最佳答案 使用反射更改值。staticvoidset

android - 使用 Espresso stub Intent 时出错

我有两个通过Intent相互交互的应用程序。我想验证一下AppA是否正确调用了AppB的startActivity而无需实际启动AppB.我已经尝试了intending的各种组合,Espresso仍然通过intent启动AppB而不是简单地将其删除。这会导致其余测试失败,因为UI被AppB阻止了。有什么想法吗?@RunWith(AndroidJUnit4.class)@LargeTestpublicclassMyActivityUiIntentsTest{@RulepublicIntentsTestRuleactivityRule=newIntentsTestRule(MyActivi