How to prevent cucumber from hatching several SpringBoot context - spring-boot

I am using Cucumber + Spring Boot + Spring Cache
Every time Cucumber jumps from one Scenario Outline to the other, my Spring Boot context is rebuilt (I can see the Banner) and my Spring Cache is rebuild... which takes a lot of time.
I tried to add #DirtiesContext above the #SpringBootTest(Web) on the java steps class, that didn't helped.
How can I prevent Cucumber from refreshing the context on each and every Scenario?
Thanks

Upgrade your Cucumber to v5 and make sure you do not have #DirtiesContext any where in your spring configuration.
https://github.com/cucumber/cucumber-jvm/tree/master/spring

Related

Spring context initialisation hangs when executing a test annotated with #SpringBootTest after a test annotated with #DataJpaTest

I think I've stumbled about a bug in either Spring, Spring Boot, Spring Data JPA or Spring Data ReST. When I execute a test annotated with #DataJpaTest before a test annotated with #SpringBootTest the initialisation of the application context of the Spring Boot test hangs. Unfortunately the minimal example to reproduce the issue is too large to be posted here, so have uploaded an example project reproducing the issue here.
I have the following questions
Is it a bug or is it a strange setup?
Is the bug already known? (I have been looking for error problems in GitHub and StackOverflow, but found nothing that fits)
If it is a bug in which project Spring Framework, Spring Boot, Spring Data Jpa or Spring Data ReST should I open a bug issue?
Thanks for your help.

#DirtiesContext not working as expected after upgrading to Spring Boot 2.2.2

I am trying to upgrade my application from Spring Boot v2.1.8 to v2.2.2. However, after upgrading some tests start failing.
The pattern of failing tests strongly indicates that #DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD), applied on test class, is failing to clear context after each test case.
I am unable to narrow down further. Will appreciate any help.
I had the same issue today. With spring boot 2.2.7 not playing nice with Dirties context. In my case, I was using DBUnit to test and it wasn’t resetting the DB.
Adding this annotation fixed it for me:
#AutoConfigureTestDatabase(replace = Replace.ANY)

Is it necessary to use a spring initializr for creating spring applications?

I have started learning about spring and in every tutorial they start from spring initializr, i was wondering is it necessary to use it or we can create a project without using spring initializr ?
No, it is no necessary. You can do everything by your own hands. It just helps you to start quicker so that you focus more on the Spring concepts instead of spending much time on "infrastructure" like configuring dependencies. You run it and it just works. Then you can extend it step by step. This can be especially helpful if you just start learning Spring. Later on you should of course spend some time on other aspects that initializr provides you.
Adding to whatever is already mentioned.
No , it is not necessary to create a project with Spring Initializr
The site provides a curated list of dependencies that you can add to
your application based on the selected Spring Boot version. You can
also choose the language, build system and JVM version for the
project.
https://spring.io/blog/2019/02/20/what-s-new-with-spring-initializr.
https://github.com/spring-io/initializr/
Using Spring Initializr the right dependencies are preconfigured for the Spring Boot version used. These preconfigured projects reduces the setup time and one can start implementing the code rather than investing time on which dependencies to go with.

Spring context cache between integration tests - slow startup times

I have a spring boot application and when I am doing some integration testing I must wait the spring context to load, for example it takes about 4 seconds for the JPA slice (I know this is not too much time). Is there a way to make this instant at least while I am developing?
e.g. something like spring-dev-tools but between integration test runs, or run a separate integration testing application, or lazy init whole spring boot context

Using Spring Boot Configuration in a custom JUnit test runner that does not otherwise use Spring

I have a custom JUnit test runner that executes acceptance-level tests using a test specification format specific to my project. The system under test is using Spring Boot and takes advantage of its configuration facility. I'd like the tests to be able to read the same configuration files in the same way. Obviously, using Spring Boot Configuration itself is an answer.
I'd like to just use Spring Boot Configuration as a stand-alone library, but I'm willing to fire up Spring Boot if that's what it takes. I'm not in control of the top-level application - JUnit is. So, I don't know how to start Spring Boot when I get control inside my test runner.
I've looked at extending SpringJunit4ClassRunner but I can't keep it from looking for #Test annotations and failing when it doesn't find any. I've started to look into merging code from SpringJunit4ClassRunner into my custom runner. Before I go too far down that path, I'd appreciate input from the community.
It sounds like you simply want the application running for a standalone webservice testing. This can be done simply by scripting the "java -jar" command to run the spring boot application. However, I would question why you don't want to leverage the testing tools built into spring boot? You can fire up the entire spring boot application and write some very logical looking tests.
For example a rest api test case:
#Test
public void homePage() throwsException () {
mockMvc.perform(get("/readingList"))
.andExpect(status().isOk())
.andExpect(view().name("readingList"))
.andExpect((model().attribute("books", is(empty()))));
}

Resources