How to use multiple classes inside #RunWith()? - spring

I am trying to run an integration test using junit4 for which I need to use #RunWith(SpringRunner.class) but I also need to use #RunWith(RunIfRunner.class) for implementing the solution mentioned here
How to ensure the use of both on these? Or is there any other way to deal with this other than using #RunWith()?
Note: I need to use the solution mentioned in the link above(check here - 1).

Related

Can I run a `#SpringBootTest` class multiple times with different configurations?

I have an integration test that's using #SpringBootTest to spin up a Spring application context that's testing a simple Spring Boot app. I'm using Spock for writing the tests, my build tool is Maven.
I'm looking for a way to run the same test class multiple times with different configurations for the test (I have a set of config options and I need to ensure consistent behavior for a certain permutation of config options). The first idea I had was to use profiles to define the exact permutation, maybe it could also work by using #TestPropertySource in some way. However, I don't see any way to run a test class multiple times, using different configurations each time.
I know that I could run all tests with a given profile, but in my case I want to only apply the different configs to certain test classes.
I can also use a where block to repeat spock tests as described here, but that doesn't allow me to switch spring configurations for each run
The easiest way is to use simple subclasses, i.e., you define all your tests in an abstract base class and then subclass it for every variation and add the necessary annotations to the subclasses. This approach works well if you only have a limited set of variations, and provides good reporting feedback as every variation is reported as its own specification.

Is there a way to enforce execution order of test classes in Junit4(5)

I am writing integration tests in a SpringBootApp with Junit5. It is a must for me to follow a execution order of REST Api calls. In one test class it is ok to use #TestMethodOrder from jUnit5 or another approach for test execution ordering in a class. My question is regard execution test classes in specific order. I found an open issue on the topic in the Junit repo https://github.com/junit-team/junit5/issues/1948 . It's not resolved. Is there a way to achieve this? I have think of #Categories introduced from Junit5 but it will be too hacky approach, it is not an option.

Can spring boot have multiple #SpringBootTest classes?

I have a use case where i want to segregate the test cases and for that, i want to use 2 test classes, each with #SpringBootTest annotation to start up the server as required.
I have tried doing so, but looks like this doesn't work.
I am unable to find it in the docs to confirm that it is really not supported.

#WithMockUser and kotlin test

I'm a big fan of Kotlintest syntax and I'd like to know if it's possible to make it work with WebMvcTest. More particularly, I don't manage to annotate the test methods with #WithMockUser.
Does somebody know if it's feasible?
Thanks beforehand.
It's not something that is currently built into KotlinTest but there is a Spring module, so it should be fairly easy to create another extension that provides this.
This is the source for the spring module.
https://github.com/kotlintest/kotlintest/tree/master/kotlintest-samples/kotlintest-samples-spring

Spring-Boot Custom Repository

I have been reading about Spring Boot custom repository. I have dozens of blogs explaining how to implement those but none of them explained scenario when we actually need it?
I mean one example where we cannot live without custom repo. I mean if there is case of complex query, we can anyhow achieve it using #Query.
Please explain.
Lets say I want strongly typed query instead of #Query. I would create a custom repo, autowire EntityManager and use QueryDSL with it so I can use strongly typed references.
You can use it to extend the repository with other libraries that aren't part of Spring.
I find them useful when working with a program generator like jHipster. They keep your code separate from the generated code.
The xxxRepositoryCustom.java xxxRepositoryImpl will not be overwritten when the entities are re-generated by a dumb programmer (me.) The queries themselves have some complex logic that can not be expressed in a simple #Query

Resources