Android中的多个入队模拟服务器API

时间:2019-03-14 09:58:45

标签: android unit-testing kotlin mockito

我正在从事单元测试。在编写测试用例时,我面临着奇怪的行为。我需要调用多个模拟API。它可以正常工作到6点,但之后无法正常工作。

@Before
    fun setUp() {
        server = MockWebServer()
        server.start()
        ApiClient.BASE_URL = server.url("/").toString()
    }

    @After
    fun tearDown() {
        server.shutdown()
    }

 @Test
    fun addHeadlineIfEmpty() {
val profilefileName = "profile_info_200_response.json"
            server.enqueue(MockResponse().setResponseCode(200).setBody(RestServiceTestHelper.getStringFromFile(context, profilefileName)))

            val employmentfileName = "profile_employment_list_200_response.json"
            server.enqueue(MockResponse().setResponseCode(200).setBody(RestServiceTestHelper.getStringFromFile(context, employmentfileName)))

            val educationfileName = "profile_education_blank_200_response.json"
            server.enqueue(MockResponse().setResponseCode(200).setBody(RestServiceTestHelper.getStringFromFile(context, educationfileName)))

            val coursefileName = "profile_course_blank_200_response.json"
            server.enqueue(MockResponse().setResponseCode(200).setBody(RestServiceTestHelper.getStringFromFile(context, coursefileName)))

            val resumefileName = "profile_resume_blank_200_response.json"
            server.enqueue(MockResponse().setResponseCode(200).setBody(RestServiceTestHelper.getStringFromFile(context, resumefileName)))


     val courseFieldfileName = "course_fields_list_200_response.json"
            server.enqueue(MockResponse().setResponseCode(200).setBody(RestServiceTestHelper.getStringFromFile(context, courseFieldfileName)))

    var addfileName = "add_education_200_response.json"
            server.enqueue(MockResponse().setResponseCode(200).setBody(RestServiceTestHelper.getStringFromFile(context, addfileName)))
}

最后一个入队API没有以某种方式调用。

0 个答案:

没有答案