mockwebserver

Mockwebserver in gradle build throwing error

痴心易碎 提交于 2020-01-02 03:33:06
问题 This entry in my gradle file : androidTestCompile ('com.squareup.okhttp:mockwebserver:2.7.0') is throwing error: Warning:Conflict with dependency 'com.squareup.okio:okio'. Resolved versions for app (1.8.0) and test app (1.6.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details. I tried commenting out different compile entries in my gradle file to find out which one was conflicting but I just can't find which one uses com.squareup.okio:okio. UPDATE: I was able to get the

MockWebServer and Retrofit with Callback

∥☆過路亽.° 提交于 2020-01-01 02:35:24
问题 I would like to simulate network communication by MockWebServer. Unfortulatelly retrofit callbacks are never invoking. My code: MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); server.play(); RestAdapter restAdapter = new RestAdapter.Builder().setConverter(new MyGsonConverter(new Gson())) .setEndpoint(server.getUrl("/").toString()).build(); restAdapter.create(SearchService.class).getCount(StringUtils.EMPTY, new Callback

How to implement MockWebServer to work with proxy

半腔热情 提交于 2019-12-22 00:25:43
问题 I am trying to implement a MockWebServer from Square and i am behind a proxy. The problem is that every time i am executing my instrumentation test will fail because i am getting a 407 for every request i am doing to my MockWebServer. debug.level.titleD/OkHttp: <-- 407 Proxy Authentication Required http://localhost:12345/user/login (767ms) As u see i am pointing to my localhost and i dont know why i am getting this! Here is my MockWebServer implementation! public class MockedTestServer {

Mock HttpResponse with Robolectric

匆匆过客 提交于 2019-12-20 19:08:08
问题 Using Robolectric 2.3-SNAPSHOT, I want to test an object that'll execute a request in the background. In order to isolate it, I'm trying to mock the HttpResponse returned, without success after some hours invested. I've created a project that anyone can clone. Simly run ./gradlew check https://github.com/Maragues/RobolectricDummyProject (git clone https://github.com/Maragues/RobolectricDummyProject.git) I've tried Robolectric.setDefaultHttpResponse(200, "my_mocked_word"); MockWebServer (https

Mock server requests Android Espresso UI Testing

这一生的挚爱 提交于 2019-12-19 03:38:04
问题 I am using Espresso to write UI tests for my Android application and would like to mock http requests using MockWebServer. I need to mock authentication responses and sign in the user before the tests are run. Is there a way make the app use mockwebserver so that isntead of making actual requests, I can use respontes enqueued on mockwebserver. So far I have: public class AuthenticationTest { @Rule public ActivityTestRule<Authentication> mActivityTestRule = new ActivityTestRule<>

Square retrofit server mock for testing

痞子三分冷 提交于 2019-12-17 17:28:13
问题 What's the best way to mock a server for testing when using the square retrofit framework. Potential ways: Create a new retrofit client and set it in the RestAdapter.Builder().setClient(). This involves parsing the Request object and returning the json as a Response object. Implement this annotated interface as a mock class and use that in place of the version provided by RestAdapter.create() (wont test gson serialisation) ? Ideally I want to have the mocked server provide json responses so I

OkHttp MockWebServer fails to accept connections when restarted

拟墨画扇 提交于 2019-12-10 04:21:36
问题 I'm using the OkHttp MockWebServer to mock my server responses for unit tests. It works great for the first test, but on the 2nd test my client fails with: Failed to connect to localhost/0:0:0:0:0:0:0:1:63631 This happens even if the 2nd test is exactly the same as the 1st one. Here's what I'm doing: @RunWith(RobolectricTestRunner.class) @Config(shadows = MyClassTest.MyNetworkSecurityPolicy.class, manifest = "src/main/AndroidManifest.xml", constants = BuildConfig.class, sdk = 16) public class

How to set MockWebServer port to WebClient in JUnit test?

允我心安 提交于 2019-12-07 20:40:00
问题 I'm using spring-boot with WebClient , which is autowired as a bean. Problem: when writing a junit integration test, I have to use okhttp MockWebServer . This mock always starts up on a random port, eg localhost:14321 . Now my WebClient of course has a fixed url that it sends the requests to. This url may be given by an application.properties parameter like webclient.url=https://my.domain.com/ , so I could override that field in a junit test. But only statically. Question: how can I reset the

How to set MockWebServer port to WebClient in JUnit test?

点点圈 提交于 2019-12-06 12:12:33
I'm using spring-boot with WebClient , which is autowired as a bean. Problem: when writing a junit integration test, I have to use okhttp MockWebServer . This mock always starts up on a random port, eg localhost:14321 . Now my WebClient of course has a fixed url that it sends the requests to. This url may be given by an application.properties parameter like webclient.url=https://my.domain.com/ , so I could override that field in a junit test. But only statically. Question: how can I reset the WebClient bean inside a @SpringBootTest so that it sends the requests always to my mock server?

OkHttp MockWebServer fails to accept connections when restarted

耗尽温柔 提交于 2019-12-05 05:59:37
I'm using the OkHttp MockWebServer to mock my server responses for unit tests. It works great for the first test, but on the 2nd test my client fails with: Failed to connect to localhost/0:0:0:0:0:0:0:1:63631 This happens even if the 2nd test is exactly the same as the 1st one. Here's what I'm doing: @RunWith(RobolectricTestRunner.class) @Config(shadows = MyClassTest.MyNetworkSecurityPolicy.class, manifest = "src/main/AndroidManifest.xml", constants = BuildConfig.class, sdk = 16) public class MyClassTest { private MockWebServer mockServer; private MyServerApi serverApi; @Before public void