-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NetworkOnMainThreadException #3184
Comments
You’ll need to avoid starting your MockWebServer on the main thread. |
But how? |
If you are confused about threading, you should take a look at this: http://stackoverflow.com/questions/6343166/how-to-fix-android-os-networkonmainthreadexception There are some good explanations, and some solutions. |
I guess you don't understand me. I know that about Maybe I will explain more what I want get. I have finished my app, couple of activties and fragments. I have class This is weird because I have Unit test where I test backend stuff and I use My first post is instrumental test but below is my unit test and it works:
|
I am not very familiar with Dagger. However, to me it looks like this method is creating You can output to logcat to determine if this is where the issue is. In these two places add the following code.
|
Class Both logs are:
|
Since both logs output true, it seems clear to me that you are creating your I am not familiar with the lifecycles of the classes you are using. However, you could attempt to initialize / start the One example:
|
It doesn't work because I tried this
In your solution and my (above) I got this:
|
No action for us to take on this. |
If anyone else stumbles on this problem here is the solution. Modify your custom AndroidJUnitRunner like so:
copied from this article. |
Hey. I know that there already is lot of similar issues but I cannot find solution.
I've started working with
Espresso
UI tests. I prepare customMockTestRunner
,MockApplication
for initializationDagger
components and I've defined mock modules too. It looks like that:MyApp
is extended byI added
testInstrumentationRunner
intogradle
I want run login tests in my
LoginActivity
This is
MockApiModule
which extendsApiModule
classAPI login request looks like that:
It works if I change
MockMyApplication
intoMyApp
class of application inMockTestRunner
When I want to run my tests I got:
The text was updated successfully, but these errors were encountered: