Giter Club home page Giter Club logo

Comments (5)

tomaszmnich avatar tomaszmnich commented on July 20, 2024 2

@andrzejchm Could you expand README tutorial with above steps? It could be helpful for the new RESTMock users.

from restmock.

andrzejchm avatar andrzejchm commented on July 20, 2024 1

the best way to understand this is to take a look into androidsample code within this repo. So:

https://github.com/andrzejchm/RESTMock/blob/develop/androidsample/src/main/java/io/appflate/restmock/androidsample/di/AppModule.java

in this dagger module, we build the retrofit object being used across the whole app. As you can see, there is a constructor parameter specifying the baseUrl. This one is being created in SampleApplication class when the app is running normally with the real url for the production servers. While running tests, I'm using TestApplication instead of SampleApplication as an Application class for the app, and there I'm specifying RESTMock's server url as a base url instead of real production url, as you can see here:
https://github.com/andrzejchm/RESTMock/blob/develop/androidsample/src/androidTest/java/io/appflate/restmock/androidsample/TestApplication.java

In order to be able to specify different Application subclass for tests and normal app run, you have to create a custom test runner, like in example: https://github.com/andrzejchm/RESTMock/blob/develop/androidsample/src/androidTest/java/io/appflate/restmock/androidsample/CustomTestRunner.java

and have it specified within your build.gradle file
testInstrumentationRunner 'io.appflate.restmock.androidsample.CustomTestRunner'
as can be seen here: https://github.com/andrzejchm/RESTMock/blob/develop/androidsample/build.gradle

from restmock.

andrzejchm avatar andrzejchm commented on July 20, 2024

First things first:

  1. Did you specify a custom test runner that starts RESTMock before the tests start?
  2. Do you perform any API call within the tests, or are those being made within the LauncherActivity? If you have those calls within launcher activity, then you will have to make sure it does have a Retrofit configuration pointing to RESTMock's url. In SomeTest you create new retrofit instance that is local to the test itself, but not to the app being tested.

from restmock.

syariffudinzo avatar syariffudinzo commented on July 20, 2024
  1. did you mean this?

b) RESTMockServerStarter

If you have your custom test runner and you can't extend RESTMockTestRunner, you can always just call the RESTMockServerStarter. Actually RESTMockTestRunner is doing exactly the same thing:

I thought it is the same thing, but I definitely will try it with both the dependencies and the RESTMockServerStarter

  1. it is being made in the LaucherActivity, and when you mean by

If you have those calls within launcher activity, then you will have to make sure it does have a Retrofit configuration pointing to RESTMock's url

does that mean i need to implement them in the main Application itself?

from restmock.

andrzejchm avatar andrzejchm commented on July 20, 2024

This is already a part of the readme as 6. point in the Setup. I will add a reference to this issue though for better explanation

from restmock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.