Debugger, #SpringBootTest, and Gradle - spring-boot

I'm new to Spring Boot and Gradle and cannot figure out how to suspend JUnit tests and connect to them with a debugger.
I invoke the automated tests on the command line gradlew build. What I'd like is so the execution to pause wen it reaches the test task and wait for a debugger to connect.
The JUnit test classes are annotated like this:
#RunWith(SpringRunner.class)
#SpringBootTest
#ActiveProfiles("test")
#AutoConfigureMockMvc
I have tried adding the JVM arguments for debugging to the gradle.properties file and I still can't get it to suspend, much less listen on a port for the debugger. I'm not sure what information to provide you -- ask me in the comments for files, code, or settings.
Gradle 5.5
Spring Boot 2.16
Java 11

#Omid. Thank you for the link. The solution was simple.
UPDATE: Do not use gradlew build. Use the test task instead.
gradlew test --debug-jvm
In the Gradle 5.5.1 docs:
https://docs.gradle.org/current/userguide/java_testing.html#sec:debugging_java_tests

Related

Maven Verify Starting and Stopping the Spring Test Runner on Each class

I am having a Spring Boot application with around ~500 Tests (Unit and mostly Integration).
When i start running the tests in IntelliJ with second click -> Run all Tests - tests run in around 10-15mins.
When i try to run the tests with "mvn verify -P itest" in IntelliJ terminal, the execution time is around an hour. This is because this command starts and stops the Spring Test Runner Server on every class (which is not my desired result).
The IntelliJ second click -> Run all Tests starts it only once.
Our Jenkins Job is running the tests with "mvn verify -P itest", so my question is how can i change this behavior, to start and stop the Test Runner only once (with this "mvn verify -P itest" command).
itest is the profile that we have in our pom.xml which includes the classes that contain integration tests (using maven failsafe plugin)
Here are the annotations of our base abstract Integration Test class
#RunWith(SpringJUnit4ClassRunner.class)
#SpringBootTest(classes = MainApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
I found this article which could by similar to my problem, but this does not explain the behavior that IntelliJ gives me.
Reset Spring-Boot During Integration Tests
Thanks a lot in advance
I found out why this was happening. There was a setting in my pom file which stated
'reuseForks' maven failsafe property to be false.
I changed it to be true and now it is working fine.
Intellij works in the same way - it is reusing the forks for all the tests.
Read More
http://maven.apache.org/surefire-archives/surefire-2.17/maven-failsafe-plugin/examples/fork-options-and-parallel-execution.html

Showing console with Spring Boot, Gradle and IDEA

Working through setting up a spring boot project with gradle and Idea. I created a Run configuration calling the bootRun gradle task. It appears to run fine (I can hit the end point) but I dont see the same console output (I don't see any) that I see when I run ./gradlew bootRun from a terminal.
What am I doing wrong?
You need to toggle (/ab) below debug button(left side of console). See this picture..

How to run junit test case after bootRun (server startup) using gradle

In my spring boot application I have junit test case. I implemented with application listener which will do certain task after server start up. Now I need to run the Junit test case after the bootRun. Basically the application runs like this., I am using gradle build script.
compile->build (running junit test cases)->bootRun
Can we run the test case after bootRun?
Thanks in advance

Running selenium unit tests with Spring Boot

I have some integration tests that use Selenium and the HtmlUnitDriver to verify my web app behaves correctly from the browser. In IntelliJ, I'm able to run ./gradlew bootRun to start my embedded web server, and then run my Selenium tests manually.
The tests run as expected.
However, I'm wondering what the best strategy is to run these in an automated fashion on my CI Server (TeamCity in this case). Simply running bootRun doesn't quite work since the task runs until it gets terminated.
Should I create a script that runs bootRun, and then I can terminate gradle somehow after the tests complete? I'd also like to use my application.properties file I have in src/test/resources instead of src/main/resources which bootRun uses normally.

IntelliJ runs unit tests with Maven instead of JUnit

I have some Unit tests, that when I try to run, it automatically creates Maven run/debug configuration, instead of JUnit (the integrated IDEA tab).
For some tests it does use JUnit run\debug configuration and manually - I can create both Maven and JUnit.
How do I make JUnit to be the default test runner ?
The problems is that I had maven runner plugin installed, causing all my tests to run with Maven
You can use the maven option "-Dskip=true" to suppress the maven test execution, and you can add your own test configuration to the build process. This screenshot was taken form IntelliJ 15.0.2.
Update: maven option

Resources