I am not extending any interface and all my interfaces are independent. While performing unit testing I am getting the following exception. During normal API calls, everything works fine.
val retrofit: Retrofit = Retrofit.Builder()
.baseUrl(url)
.client(httpBuilder.build())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
return retrofit.create(MyApi::class.java)
The exception is thrown at retrofit.create(..)
only while performing the unit test. Is there a way to avoid this error?
This can be fixed by using dependency injection for getting Service inside the method to be tested instead of creating the instance within the method.