Tag: mockwebserver

由于NoClassDefFoundError而导致的工具测试失败

我从今天开始在调试模式下对我的kotlin应用程序进行多重分解,因为库迫使我这样做。 我的问题是,我的用户界面测试不工作了。 我也正在缩小我的apk。 我收到以下错误: FATAL EXCEPTION: MockWebServer Process: [package], PID: 19446 java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/collections/CollectionsKt; at [package].activity.MockedServerTestsBase$dispatcher$1.dispatch(Unknown Source) at okhttp3.mockwebserver.MockWebServer$3.processOneRequest(Unknown Source) at okhttp3.mockwebserver.MockWebServer$3.processConnection(Unknown Source) at okhttp3.mockwebserver.MockWebServer$3.execute(Unknown Source) at okhttp3.internal.NamedRunnable.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) Caused by: java.lang.ClassNotFoundException: Didn’t find class “kotlin.collections.CollectionsKt” on path: DexPathList[[zip file “/system/framework/android.test.runner.jar”, zip file “/data/app/[package].test-2/base.apk”, zip file “/data/app/[package]-1/base.apk”],nativeLibraryDirectories=[/data/app/[package].test-2/lib/x86, […]

为什么这个Android Instrumentation测试调用Activity两次创建?

我有这个测试课: class InspirationalQuoteInstrumentedTest { private lateinit var server: MockWebServer @Rule @JvmField val mActivityRule: ActivityTestRule<InspirationalQuoteActivity> = ActivityTestRule(InspirationalQuoteActivity::class.java) @Before fun setUp() { server = MockWebServer() server.start() Constants.BASE_URL = server.url("/").toString() } @After fun tearDown() { server.shutdown() } @Test fun ensureTheQuoteOfTheDayIsDisplayed() { println("Base URL: ${Constants.BASE_URL}") Log.e(TAG,"Base URL: ${Constants.BASE_URL}") val response200 = this::class.java.classLoader.getResource("200.json").readText() val jsonResponse = JSONObject(response200) val expectedQuote = […]

如何使MockWebServer工作?

我正在开发一个使用MVP架构的应用程序。 我正在尝试使用MockWebServer来测试我的应用程序的交互器。 那么,我有这个测试: @RunWith(RobolectricTestRunner::class) @Config(constants = BuildConfig::class, manifest = "src/main/AndroidManifest.xml", packageName = "br.com.simplepass.simplepassnew", sdk = intArrayOf(23)) class LoginInteractorImplTest { lateinit var mLoginInteractor : LoginInteractor lateinit var mServer: MockWebServer @Before fun setUp(){ mLoginInteractor = LoginInteractorImpl() mServer = MockWebServer() mServer.start() } @Test fun loginTest(){ mServer.url("http://192.168.0.10:8080/login") val testSubscriber = TestSubscriber.create<User>() mLoginInteractor.login("31991889992", "lala").subscribe(testSubscriber) testSubscriber.assertNoErrors() // testSubscriber.assertCompleted() } @After fun […]

MissingMethodInvocationException在Kotlin中测试已打开的类

我正在尝试使用Kotlin + RxJava和MockWebServer进行一些集成测试。 我在测试方面是一个新手,我是Kotlin学徒。 我知道Mockito和final类的局限性,但我不应该嘲笑我正在测试的类,所以我不知道真正的问题在哪里: 错误如下: Apr 16, 2016 9:59:49 PM okhttp3.mockwebserver.MockWebServer$3 execute INFO: MockWebServer[54260] starting to accept connections Apr 16, 2016 9:59:50 PM okhttp3.mockwebserver.MockWebServer$3 acceptConnections INFO: MockWebServer[54260] done accepting connections: Socket closed org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'. For example: when(mock.getArticles()).thenReturn(articles); Also, this error might […]