使用 Gradle 从 CLI 运行 Spring Boot 测试

Ste*_*ike 4 java gradle spring-boot

我正在学习 Spring Boot,并且有一个关于如何从 CLI 运行的初学者问题。

在 IntelliJ 中,当使用 JUnit 运行配置或从右键单击上下文菜单中时,我在控制台中看到 Spring Boots 的独特徽标。如果我使用.gradlew clean test测试运行完全相同,但没有任何 spring-y 的东西。

测试类:

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

    @Autowired
    private MainPage mainPage;

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

    @Autowired
    private WebDriver driver;


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

}
Run Code Online (Sandbox Code Playgroud)

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"
    }
}
Run Code Online (Sandbox Code Playgroud)

抱歉,新手问题 - 我如何引导它从 Gradle 良好地运行,以便我可以开始从 CI 上下文(Jenkins)运行?

ath*_*hom 8

默认情况下运行gradlew clean test你不会看到很多输出。

与你一起运行gradlew clean test --info会看到更多输出,包括 Spring 徽标