question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android application scope getting reset after test

See original GitHub issue

Suppose 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 @Mocks 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
stephanenicolascommented, Jun 13, 2017

@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:

A small note/gotcha for visitors to this issue. Having a child scope implies you might need a custom @Singleton annotation. By default, @Singleton annotated objects are automatically attached to the root scope here.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stephanenicolas/toothpick/issues/188#issuecomment-308124130, or mute the thread https://github.com/notifications/unsubscribe-auth/ABv33aaOnOrDOkMmceeZSbLXZ_Pt2bzXks5sDpUggaJpZM4Lg-Ay .

0reactions
stephanenicolascommented, Oct 14, 2017

I close this topic as it was addressed in 1.1.x

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found