Android application scope getting reset after test
See original GitHub issueSuppose I create a global application scope from my Android Application
class, e.g.
@Override
public void onCreate() {
super.onCreate();
Scope appScope = Toothpick.openScopes(APP_SCOPE);
appScope.installModules(
new SmoothieApplicationModule(this),
new MyAppModule(this));
);
}
Suppose this global scope is used everywhere in my app.
In my instrumentation tests, I want to mock out some of the instances provided by MyAppModule
. If I use ToothPickRule
in my tests, so that I get the auto-binding of @Mock
s from ToothPickTestModule
, the entire Toothpick scope gets reset after each test. Since the Application.onCreate()
is only called once, I lose any modules I installed in that scope.
What would be the recommended approach here?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Coroutine scope on Application class android - Stack Overflow
If it is just CPU background work, use Dispatchers. Default. Of course, you can redefine the scope with withContext() method or launch method....
Read more >Use Kotlin coroutines with lifecycle-aware components
Any coroutine launched in this scope is automatically canceled if the ViewModel is cleared. Coroutines are useful here for when you have work ......
Read more >Making permissions auto-reset available to billions more ...
Permissions are reset by default for apps targeting Android 11 or later. ... Check if permission auto-reset is enabled on the device ...
Read more >Unit Testing with Kotlin Coroutines: The Android Way - Medium
In our app testing strategy, Unit tests are the fundamental tests. ... This scope is tied to the ViewModel and will be canceled...
Read more >Resetting, Checking Out & Reverting | Atlassian Git Tutorial
We explore the three trees in depth on the git reset page. ... The git checkout command can be used in a commit,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Singleton is THE annotation that allows to create Singletons for the root scope. Any other scope needs a custom annotation and to bind the annotation scope to the scope. Thx Etienne for this precision.
2017-06-13 6:56 GMT-07:00 Etienne Caron notifications@github.com:
I close this topic as it was addressed in 1.1.x