android-test icon indicating copy to clipboard operation
android-test copied to clipboard

Remove need to initialize and teardown Intents support

Open brettchabot opened this issue 6 years ago • 3 comments

brettchabot avatar Jan 09 '19 02:01 brettchabot

@brettchabot Just so I'm clear on this one; this is regarding the Intents.init() and Intents.release() calls inside IntentsTestRule, correct?

dmeng avatar Mar 18 '19 22:03 dmeng

What we'd like to do is use ServiceLoader to dynamically initialize this if the library is on the classpath. We'd like to do the same thing for the Accessibility support too and possibly use the plugin API to handle this. I was going to pair with Christian on this next week to see if it makes sense.

jongerrish avatar Mar 29 '19 15:03 jongerrish

One thing that would help here would be to just add an updated or alternative version of IntentsTestRule that manages the init and release calls. For instance:

class RecordedIntentsRule : TestRule {
    override fun apply(base: Statement, description: Description): Statement {
        return object : Statement() {
            override fun evaluate() {
                try {
                    Intents.init()
                    base.evaluate()
                } finally {
                    Intents.release()
                }
            }
        }
    }
}

This would make it easier to write tests using Intents and ActivityScenario (as opposed to IntentsTestRule which extends the old ActivityTestRule) without needing to rework Intents.

seadowg avatar Jun 02 '22 13:06 seadowg