In intelliJ Run/Debug Configuration, how to skip spring boot tests - spring-boot

We have written tests using annotations like below,
#RunWith(SpringRunner.class)
#Slf4j
#SpringBootTest
in IntelliJ 2017 we run spring boot program via Run/Debug Configuration, and it automatically execute these tests. But some tests really takes a lot of time, is there a way to disable or skip these tests? Thanks a lot.

You can write a junit category of runners or right click on package name or test-class and choose Run "yourClassName", which will run only this class or all classes from selected package.

Related

Spring integration test has different behaviour when started via IntelliJ run configuration and via mvn verify

I am working on the Spring application based on Spring Boot 2.6.7 (Spring framework version 5.3.19). I noticed that when I run the integration test via IntelliJ run configuration (basically created only by the right clicking on the test method name and choosing Run test) then the same instance of the ApplicationContext is used in the integration test class and in the actual SpringBootApplication which is tested by the integration test.
But when the same integration test is executed from the command line via mvn verify command, then the different instance of the ApplicationContext is active in the Spring Boot Application from the one which is active in the integration test class.
That for example has a consequence that spring data repository which I added as a field to the integration test class with #SpyBean annotation is not not applied in the Spring boot application. In the applicationContext of the integration test class, that spring data repository is registered as a spy but in the application context of the Spring Boot Application there is no spy proxy but the regular repository.
On the other hand when the test is running via IntelliJ run configuration, the applicationContext is same everywhere and the spy bean is active in the Spring Boot Application flow.
So I want to achieve the same behavior when I run mvn verify as I achieve when I run the test from IntelliJ. Any ideas?

IntelliJ runs wrong Spring Boot class

I'm working on a Spring Boot project with IntelliJ IDEA (2021.3.1, community edition). I have two classes annotated with #SpringBootApplication. One's the main application, and the other is a utility for helping build up the database I'm using.
I've been trying to run the utility from IntelliJ with an Application configuration. I have the utility class specified in that configuration as the one to run. But IntelliJ runs the main application class instead.
I tried taking the #SpringBootApplication off my main class, and then the run configuration would run the utility. I put the annotation back on my main class, and the run configuration ran the utility and the main class.
I am absolutely stumped. Is "Application" the wrong kind of run configuration? Is there something else I need to be setting up to get it to run the right class?

junit test case for spring-integration-file

Am newbie to Spring. I have a spring project created using spring-integration-file (spring boot- FTP,SFTP,NFS) which will transform the file from source path to destination path.
Have to write junit test cases to test the project. It will be helpful if someone share some documents/link to write junit testcases with #RunWith(SpringRunner.class) for spring-integration-file project
Thanks in advance
You can consult Spring Integration Samples project on the matter.
Also there are a lot of JUnit tests in the spring-integration-file module of the core project per se.

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()))));
}

running integration tests in teamcity using spring-boot and restassured

I am writing my integration tests using springboot and rest-assured and using SpringApplicationConfiguration to load the configuration.
This is what the test class annotation look like:
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = RestAPIApplication.class)
#IntegrationTest("server.port:8083") // this is the port set by my application
Now comes my real question. When I run the test class in teamcity using maven, don't I have to configure something to run the springboot server before running the integration tests?
I am new to springboot so maybe this question is very novice but please point me to the correct path.
If you're using embedded tomcat, no extra setup is needed-- simply run the maven tests.

Resources