0

I have done API testing as sample application as shown in bellow code with using wiremock. but i have get numberFormat exception and invalide int as shown in bellow this error please give me any suggestion

@RunWith(AndroidJUnit4.class)
public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {

    public MainActivityTest()
    {
        super(MainActivity.class);
    }

    @Override
    @Before
    public void setUp() throws Exception
    {
        super.setUp();
        injectInstrumentation(InstrumentationRegistry.getInstrumentation());
        getActivity();
    }

    private static void stubServerCall() throws Exception
    {

       //WireMock.configureFor(Integer.parseInt(serverURL));
       WireMock.configureFor(Integer.parseInt("http://androidexample.com/media/webservice/JsonReturn.php"));
        stubFor(get(urlEqualTo("/tree/getLocalePack"))
                .willReturn(aResponse()
                        .withStatus(HttpStatus.ORDINAL_200_OK)
                        .withHeader("Content-Type", "text/xml")
                        .withBody("<response>This is mock response</response>")));
    }

    @Test
    public void testSendRequestEspresso() throws Exception
    {
        stubServerCall();

        onView(withId(R.id.returnStringLbl)).check(matches(withText("Nothing yet returned")));

        onView(withId(R.id.sendRequest)).perform(click());


    }
}
java.lang.NumberFormatException: Invalid int: "http://androidexample.com/media/webservice/JsonReturn.php"
at java.lang.Integer.invalidInt(Integer.java:137)
at java.lang.Integer.parse(Integer.java:374)
at java.lang.Integer.parseInt(Integer.java:365)
at java.lang.Integer.parseInt(Integer.java:331)
at com.example.prashant.prashant.MainActivityTest.testSendRequestEspresso(MainActivityTest.java:80)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:54)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:228)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1710)

Tests ran to completion.
Suraj Makhija
  • 1,376
  • 8
  • 16
  • It seems there are some problem in your parameters which are you passing. –  Mar 23 '17 at 08:29
  • What are those please give me suggestion... – Prashant pattar Mar 23 '17 at 08:34
  • I'm not able to see any parameters . I think it hits directly a Url. What is your line java:137 as seen in your available log. –  Mar 23 '17 at 08:39
  • Check these examples: https://github.com/handstandsam/AndroidHttpMockingExamples/tree/master/app/src/androidTest/java – arkus Mar 23 '17 at 08:40
  • Running tests $ adb shell am instrument -w -r -e debug false -e class com.example.prashant.apitry.handstandsam.httpmocking.tests.RealServerTest com.example.prashant.apitry.test/android.support.test.runner.AndroidJUnitRunner Client not ready yet.. Started running tests Test running failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError' Empty test suite. – Prashant pattar Mar 23 '17 at 09:13
  • I have get this above error when i m going to run the test app – Prashant pattar Mar 23 '17 at 09:13

0 Answers0