Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Sporadic IllegalStateException #209
I'm new to Citrus but very impressed so far. We're trying to use the Cucumber integration with supplied glue. I've been seeing a sporadic "java.lang.IllegalStateException: Unable to initialize Citrus instance - instance has already been initialized" when running the IT as a JUnit test on my development system (Windows/Eclipse) and sometimes less frequently when running the Maven integration-test goal, again on my local system. The problem is much worse in our Jenkins environment. I can't get a clean project build that exercises the tests because it always fails with the IllegalStateException. I'm using Citrus 2.6.2 and JDK 1.7, though I tried Citrus 2.7 and JDK 1.8 with no appreciable difference. Not sure what else you need to know or what files you need me to post. Already RTFM and STFW with no helpful results.
citrus-context.xml -- only defining a single HTTP endpoint that uses basic auth.
The cucumber feature file is pretty simple with only one scenario that sends and receives a message on an autowired Spring endpoint defined in citrus-context and a background that defines the the request message and response message templates used by the scenario.
I have a demo to senior management on Monday and wanted to show off Citrus and Cucumber in Jenkins but can't get it to work and starting to get a little desperate. I'll be watching the board through the weekend should anyone have a suggestion or need more information. Thanks!
First question: do you need to use Spring autowiring in StepDefinition classes? If not use
Secondly your initialization is called multiple times unexpectedly. So Citrus runtime is loaded at least twice and the error is raised. So you may need to give your Cucumber Java class that loads the Spring application context. I would expect something like:
In the step definitions you may use something like:
Do you have multiple StepDefinition classes? You should have
Changing the ObjectFactory did the trick. We were using custom steps classes but I wanted to see how far we could get with using the provided steps. I thought I had tried changing this property but it was a long day Friday. It's good to know that the ContextConfiguration annotation can appear on only one feature per package.
My remaining problems appear to be Jenkins or application related now. Thanks again for your quick response.
Some additional note: When using cucumber-spring in combination with Citrus please make sure that cucumber-spring library is loaded in classpath before Citrus. You can put the cucumber-spring dependency in Maven POM before Citrus dependency. This should also fix the IllegalStateException when executing tests with Maven. Also in IntelliJ you can fix the classpath order of libraries loaded.
This is because cucumber-spring initialization should be done before the Citrus cucumber extension is loaded. Only the the Spring application context setup is done properly. In case you do not use cucumber-spring you can ignore all of this.