Closed dawidhyzy closed 6 months ago
You are missing @WithJunitRule annotation. Also better place rules in separate file. Check readme and cuculator sample
I checked cukeulator before but it's hard to understand which steps are needed and which are showcase of different approach. I moved the Compose rule to a separate class:
// ComposeRuleHolder.kt
@WithJunitRule
@Singleton
class ComposeRuleHolder @Inject constructor() {
@get:Rule(order = 1)
val composeTestRule = createAndroidComposeRule<HiltAppCompatActivity>()
}
And updated the steps accordingly:
@HiltAndroidTest
class Steps(
val composeRuleHolder: ComposeRuleHolder
) : SemanticsNodeInteractionsProvider by composeRuleHolder.composeTestRule {
private val composeTestRule
get() = composeRuleHolder.composeTestRule
@Given("I open the App")
fun I_open_the_App() {
composeTestRule.setContent {
Box(Modifier.testTag("Tv").fillMaxSize()) {
Box(
modifier = Modifier
.size(100.dp)
.align(Alignment.Center)
.background(Color.Blue)
)
}
}
}
@Then("The TV tab is displayed")
fun Then_the_TV_tab_is_displayed() {
onNodeWithTag("Tv").assertIsDisplayed()
}
}
I keep getting the same exception. I tried adding @WithJunitRule
to both rule holder and steps class but id didn't help.
I need to check if createAndroidComposeRule
could be somehow incompatible. Can you check with createComposeRule
. I'm not sure why you need specific activity while you're setting custom composable in test
I tried createAndroidComposeRule
and got the same result.
There are two reasons for using a specific activity
AppCompatActivity
https://developer.android.com/guide/topics/resources/app-languagesFor backward compatibility with previous Android versions, equivalent APIs are also available in AndroidX. However, the backward compatible APIs work with the AppCompatActivity context
I was checking the pull request and it looks like the cukeulator uses the latest changes that I think are not part of version 7.14.0 could that be a problem?
Could be, I've tested locally with latest version and createAndroidComposeRule
works fine
But imho the only difference is that @Singleton and @Inject annotation in ComposeRuleHolder is actually ignored in version 7.14.0
@lsuski I found the problem. I had my steps in my.test.steps
and test rules holder in my.test.rule
packages. This was causing the NullPointerException
despite options pointing to the right package @CucumberOptions(glue = ["my.test.steps"], features = ["features"])
. After moving everything to the same package as the test runner and removing glue from the options everything works as expected. Is that a bug or my mistake? If it is a bug I can create a branch which reproduces this behaviour or provide more info.
it is a mistake, glue
points to package where cucumber can find steps, hooks, rules etc.. You can specify more than one package if you want
I get a null pointer exception when executing the tests. If I write the same test without
Cucumber
and use plainAndroidJUnitRunner
the test as supposed toπ What did you see?
β What did you expect to see?
Test runs
π¦ Which tool/library version are you using?
io.cucumber:cucumber-android io.cucumber:cucumber-android-hilt
π¬ How could we reproduce it?
Feature file
Steps to reproduce the behavior:
NullPointerException
π Any additional context?
Plain Compose test to compare.