A Torre
A Torre

Reputation: 219

Intellij, cucumber test and two spring Context Configuration

My project has two different cucumber test and each one needs a different spring context configuration.

The problem I have is that when I run each test individually from Intellij, they load the right Spring Context and the tests are passing, but I press run all test, none of them are passing.

Running a maven test, both test are passing.

this is my code:

@RunWith(FCSCucumber.class)
@Cucumber.Options(strict = true
//        , tags = {"~@ignore"}
//        , tags = {"@Only"}
        , glue ="feature.scenario1"
        , features = "src/test/resources/feature/scenario1/"
)
@FCSApplicationProperties(commonProps="config/scenario1/exec.common.properties",
        environmentProps="src/test/resources/scenario1-test.properties")
public class TesScenario1Features {
	
}

@ContextConfiguration("/cucumber-scenario1.xml")
public class scenario1Steps {
......
}

@RunWith(FCSCucumber.class)
@Cucumber.Options(strict = true
//        , tags = {"~@ignore"}
//        , tags = {"@Only"}
        , glue ="feature.scenario2"
        , features = "src/test/resources/feature/scenario2/"
)
@FCSApplicationProperties(commonProps="config/scenario2/exec.common.properties",
        environmentProps="src/test/resources/scenario2-test.properties")
public class TesScenario2Features {
	
}

@ContextConfiguration("/cucumber-scenario2.xml")
public class scenario2Steps {
......
}

Thank you very much for your help

Upvotes: 4

Views: 2428

Answers (1)

Jörn Horstmann
Jörn Horstmann

Reputation: 34014

The issue is that the IntelliJ cucumber plugin is using the cucumber cli to run tests, without using the JUnit runner at all. This causes several limitations, like requiring the spring annotations on the step definition classes instead of the runner, or by default requiring the steps definitions to be in the same package as the scenario files.

In your example I would actually expect also running a single test to fail, unless the correct application properties are also referenced by the /cucumber-scenario{1,2}.xml files.

The only option I see with the standard cucumber implementation would be to extract the tests into separate projects.

I'm actually working on an alternative implementation of cucumber with an improved spring integration that you might want to try. It's not fully integrated with IntelliJ yet though.

Upvotes: 1

Related Questions