1. Thank you for great article, How do you create jar and run from command line ?

    1. Author

      The most common option to run these tests from the command line is to simply use maven so they will run as part of the build.
      $ mvn clean test
      If you really want to run tests from within the jar file, check this link.

  2. Now how do you use @Autowired. It is null in step definitions file when trying to auto wire a Apache Camel ProducerTemplate.

  3. After a lot of researching on web, first example that works cucumber-spring boot integration!

  4. How about running cucumber agains a remote server ?

  5. Thank you so much, this is the one blog post which helped me getting my cucumber test case running with ‘io.cucumber’ dependency. Many other blogs are using ‘info.cukes’ dependencies, even though its years old. Thanks much.

  6. I have a custom runner that extends BlockJUnit4ClassRunner to allow me to inject specific Spring beans into certain tests. I want to be able to inject these beans into my step defs, so I tried building the same structure as your guide but having SpringBootBaseIntegrationTest run with my XYZRunner instead of SpringRunner.

    When I debug the test from BagCucumberIntegrationTest it gets into my step definition functions but it never runs the constructor of XYZRunner. The structure is BagCucumberIntegrationTest extendsSpringBootBaseIntegrationTest, [email protected](XYZRunner.class)`. Do you have any ideas?

    1. Author

      Is it an open source project? Just send me the link and I will have a look, otherwise it’s difficult to figure out what is going wrong… Maybe you could also use different configurations so you get different beans injected into your tests.

  7. Thanks for this great article.
    Do you have an idea of how to make the tests Transactional for Rollback database changes at the end of a scenario. typically in my springboot junit tests i use the Transactional annotation. transactionaltestexecutionlistener does the magic.
    how can i use similar behaviour Here?


  8. I unfortunately have been unable to get cucumber to play ball with Spring Boot 2, I have tried using the same cucumber setup you have but I run into an initializationError when I run gradlew test. If I include the @Ignore on my steps class the test just skips completely and there is no output from cucumber. Any thoughts?

    1. Author

      I’m certainly not a gradle expert and I didn’t try to use it in this setup, but have you tried the setup described in this link? You can also point me to the code if it’s public and I can have a look.

  9. its my own code with the same approach that you talked about. I am running the test class with @RunWith(Cucumber.class)

    below is how my step’s parent class looks like.

    @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

    public class AbstractDefs {

    I had used the same dependencies that you had mentioned.

    1. Author

      I think I know what might be happening, I just reproduced that exception by removing the annotation @SpringBootApplication from the code’s main class (in my case SpringBootCucumberApplication). Check that your code (your main code, not the tests) has a proper configuration (e.g. are you missing the annotation?). Does the application start? If it does, then it might be that some configuration is overridden while running the tests.

  10. very good article. I was also looking for the same solutions. I tried with the approach, but I am getting an error with the below exception.

    java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test

    1. Author

      Are you trying the same code or your own? Check which test class you’re running (the one with @RunWith(Cucumber.class)) and the class annotations (the steps’ parent class is annotated with @SpringBootTest).


This site uses Akismet to reduce spam. Learn how your comment data is processed.