Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Spring Boot Tests from CLI using Gradle

I am learning Spring Boot and have a beginner's question on how to run from CLI.

In IntelliJ, when using the JUnit run configuration or from the right-click context menu, I see Spring Boots's distinctive logo in the console. If I run using .gradlew clean test the test runs exactly the same but without any spring-y stuff.

Test Class:

@SpringBootTest
@Profile("dev")
class SpringBasicApplicationTests {

    @Autowired
    private MainPage mainPage;

    @Value("${app.url}")
    private String appUrl;

    @Autowired
    private WebDriver driver;


    @Test
    void performLoginTest() {
        mainPage.performLogin();
    }

}

build.gradle

plugins {
    id 'org.springframework.boot' version '2.4.5'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id 'io.freefair.lombok' version '5.3.0'
}
apply plugin: 'io.spring.dependency-management'

group = 'com.ea'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter:2.4.3'
    implementation 'io.github.bonigarcia:webdrivermanager:3.8.1'
    implementation 'org.seleniumhq.selenium:selenium-java:3.141.59'
    testImplementation 'org.springframework.boot:spring-boot-starter-test:2.4.3'
    testImplementation 'org.testng:testng:7.1.0'
    testImplementation 'org.testcontainers:junit-jupiter:1.15.1'
    testImplementation 'org.testcontainers:selenium:1.15.1'
}

test {
    useJUnitPlatform()
    filter{
        includeTestsMatching "com.ea.SpringBasic.SpringBasicApplicationTests"
    }
}

Sorry for the noob question - how do I bootstrap this to run nicely from Gradle so I can start to run from a CI context (Jenkins)?

like image 216
Steerpike Avatar asked Oct 20 '25 13:10

Steerpike


1 Answers

By default running gradlew clean test you won't see a lot of output.

Running with gradlew clean test --info you will see more output, including the Spring logo

like image 181
athom Avatar answered Oct 22 '25 04:10

athom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!