You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
E/RESTMock: <- Response ERROR: NOT MOCKED: GET /ServiceStatus HTTP/1.1
Below is my code
@rule
public ActivityTestRule mActivityRule = new ActivityTestRule<>(HomePageActivity.class,false,true);
@Before
public void init() {
//be sure to reset it before each test!
RESTMockServer.reset();
}
@Test
public void shouldDisplayUpgradeRequiredMessage() {
RESTMockServer.whenGET(pathContains("ServiceStatus"))
.thenReturnFile(200, "ServiceStatus.json");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
RequestsVerifier.verifyGET(pathEndsWith("ServiceStatus.json")).exactly(1);
onView(ViewMatchers.withId(R.id.tvServiceMessage)).check(matches(withText(UpgradeMessage)));
}
This is the detailed stacktrace
04-25 19:55:28.008 17309-17309/CommCore.avv.Debug D/LifecycleMonitor: Lifecycle status change: CommCore.avv.app.homepage.HomePageActivity@c0dfeb5 in: STARTED
04-25 19:55:28.009 17309-17340/CommCore.avv.Debug D/OkHttp: --> GET http://localhost:44683/ServiceStatus http/1.1
04-25 19:55:28.009 17309-17340/CommCore.avv.Debug D/OkHttp: Referer: http://localhost:44683/?OS=Android&OSVersion=7.1.1&Make=unknown&Model=Android SDK built for x86&AppVersion=4.05.0&ScreenWidth=1080&ScreenHeight=1776&UUID=641c8afde8f574b1
04-25 19:55:28.009 17309-17340/CommCore.avv.Debug D/OkHttp: --> END GET
04-25 19:55:28.010 17309-17309/CommCore.avv.Debug D/LifecycleMonitor: Lifecycle status change: CommCore.avv.app.homepage.HomePageActivity@c0dfeb5 in: RESUMED
04-25 19:55:28.022 17309-17341/CommCore.avv.Debug D/RESTMock: -> New Request: GET /ServiceStatus HTTP/1.1
04-25 19:55:28.022 17309-17341/CommCore.avv.Debug E/RESTMock: <- Response ERROR: NOT MOCKED: GET /ServiceStatus HTTP/1.1
04-25 19:55:28.023 17309-17341/CommCore.avv.Debug I/MockWebServer: MockWebServer[44683] received request: GET /ServiceStatus HTTP/1.1 and responded: HTTP/1.1 500 Server Error
04-25 19:55:28.024 17309-17340/CommCore.avv.Debug D/OkHttp: <-- 500 Server Error http://localhost:44683/ServiceStatus (15ms)
The text was updated successfully, but these errors were encountered:
1: You mock request http://localhost:44683/ServiceStatus and verify if a request with path that ends with ServiceStatus.json is called (mind the .json ending in verifier)
2: You specified your test rule to start the activity automatically for each test. This means that the first line of your test is going to be executed after your activity starts. If your activity performs those requests in onCreate or onStart or event in onResume then they will be fired before you even manage to mock those tests in MockWebServer. To fix that, replace new ActivityTestRule<>(HomePageActivity.class,false,true); with new ActivityTestRule<>(HomePageActivity.class,false,false); (mind the false at third parameter). and start your activity manually in the test AFTER you specify mocks with mActivityRule.launchActivity(null), so it would look something like this:
@RulepublicActivityTestRulemActivityRule = newActivityTestRule<>(HomePageActivity.class,false,false);
@Beforepublicvoidinit() {
//be sure to reset it before each test!RESTMockServer.reset();
}
@TestpublicvoidshouldDisplayUpgradeRequiredMessage() {
RESTMockServer.whenGET(pathContains("ServiceStatus"))
.thenReturnFile(200, "ServiceStatus.json");
mTestRule.launchActivity(null);
try {
Thread.sleep(2000);
} catch (InterruptedExceptione) {
e.printStackTrace();
}
RequestsVerifier.verifyGET(pathEndsWith("ServiceStatus.json")).exactly(1);
onView(ViewMatchers.withId(R.id.tvServiceMessage)).check(matches(withText(UpgradeMessage)));
}
Why I get the below error.
E/RESTMock: <- Response ERROR: NOT MOCKED: GET /ServiceStatus HTTP/1.1
Below is my code
@rule
public ActivityTestRule mActivityRule = new ActivityTestRule<>(HomePageActivity.class,false,true);
This is the detailed stacktrace
04-25 19:55:28.008 17309-17309/CommCore.avv.Debug D/LifecycleMonitor: Lifecycle status change: CommCore.avv.app.homepage.HomePageActivity@c0dfeb5 in: STARTED
04-25 19:55:28.009 17309-17340/CommCore.avv.Debug D/OkHttp: --> GET http://localhost:44683/ServiceStatus http/1.1
04-25 19:55:28.009 17309-17340/CommCore.avv.Debug D/OkHttp: Referer: http://localhost:44683/?OS=Android&OSVersion=7.1.1&Make=unknown&Model=Android SDK built for x86&AppVersion=4.05.0&ScreenWidth=1080&ScreenHeight=1776&UUID=641c8afde8f574b1
04-25 19:55:28.009 17309-17340/CommCore.avv.Debug D/OkHttp: --> END GET
04-25 19:55:28.010 17309-17309/CommCore.avv.Debug D/LifecycleMonitor: Lifecycle status change: CommCore.avv.app.homepage.HomePageActivity@c0dfeb5 in: RESUMED
04-25 19:55:28.022 17309-17341/CommCore.avv.Debug D/RESTMock: -> New Request: GET /ServiceStatus HTTP/1.1
04-25 19:55:28.022 17309-17341/CommCore.avv.Debug E/RESTMock: <- Response ERROR: NOT MOCKED: GET /ServiceStatus HTTP/1.1
04-25 19:55:28.023 17309-17341/CommCore.avv.Debug I/MockWebServer: MockWebServer[44683] received request: GET /ServiceStatus HTTP/1.1 and responded: HTTP/1.1 500 Server Error
04-25 19:55:28.024 17309-17340/CommCore.avv.Debug D/OkHttp: <-- 500 Server Error http://localhost:44683/ServiceStatus (15ms)
The text was updated successfully, but these errors were encountered: