Reputation: 138
I would like to call some methods before run all tests. Library provides initializer which preparing device to use:
SomeLibraryInitializer.init(new SomeLibraryInitializer.Callback() {
@Override
public void onFinish() {
}
});
The library is ready to use when onFinish is called.
Can't mock library classes (proguard in use), so I have to use that initializer for my JUnit tests
.
Is there any way to wait until callback onFinish()
is called?
Tried with ShadowApplication.runBackgroundTasks();
and Semaphore, but not seem to work.
I'm using @BeforeClass
Annotation to run it before all tests.
Upvotes: 1
Views: 337
Reputation: 2075
What you want is to extend AndroidJUnitRunner and then set it int build.gradle
file like
android {
defaultConfig {
testInstrumentationRunner "com.example.MyTestRunner"
}
}
EDIT
If you look at the source you will see onCreate
method that is called once. What you want to do is owerride this method and add your own logic in it. Then when you are done you should call start()
metho.
Upvotes: 1