Skip to content
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

Hilt and Cucumber tests #81

Closed
sylwek845 opened this issue Jul 12, 2021 · 3 comments · Fixed by #88
Closed

Hilt and Cucumber tests #81

sylwek845 opened this issue Jul 12, 2021 · 3 comments · Fixed by #88

Comments

@sylwek845
Copy link

Describe the bug
Trying to run Dagger Hilt Rule and Cucumber tests, and it seems like the Hilt Rule is not getting invoked. Hilt Injection seems to be working without cucumber with exact the same setup.

Thats my custom runner

class ScreenshotTestRunner : CucumberAndroidJUnitRunner() {
    override fun onCreate(bundle: Bundle?) {
        super.onCreate(bundle)
        ScreenshotRunner.onCreate(this, bundle)
        ComposeScreenshotRunner.onCreate(this)
    }

    override fun onDestroy() {
        ScreenshotRunner.onDestroy()
        super.onDestroy()
    }

    override fun finish(resultCode: Int, results: Bundle?) {
        ScreenshotRunner.onDestroy()
        ComposeScreenshotRunner.onDestroy()
        super.finish(resultCode, results)
    }

    override fun newApplication(
        cl: ClassLoader,
        appName: String,
        context: Context
    ): Application {
        return super.newApplication(
            cl, HiltTestApplication::class.java.name, context
        )
    }
}

Additional context
Add any other context about the problem here.

@lsuski
Copy link
Contributor

lsuski commented Jul 13, 2021

Cucumber is built on top of Junit but in general it is recommended to use cucumber's @Before @After annotations. I think that junit rules will not work here - maybe they could work with some modifications in CucumberJUnitRunner. You can try to invoke hilt rule methods in @io.cucumber.java.Before and @io.cucumber.java.After hooks to simulate normal junit behaviour.

@sylwek845
Copy link
Author

sylwek845 commented Jul 14, 2021

@lsuski Thanks, I think the problem is that the rule needs Statement and Description which usually is taken from TestRule apply method. It would be good to have a Rule.

lsuski added a commit that referenced this issue Oct 4, 2021
@lsuski lsuski mentioned this issue Oct 4, 2021
6 tasks
@lsuski lsuski closed this as completed in #88 Oct 4, 2021
@lsuski
Copy link
Contributor

lsuski commented Oct 4, 2021

Will be available in 4.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants