gpt4 book ai didi

java - 使用 Gradle 从 CLI 运行 Spring Boot 测试

转载 作者:行者123 更新时间:2023-12-02 18:45:24 26 4
gpt4 key购买 nike

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

在 IntelliJ 中,当使用 JUnit 运行配置或从右键单击上下文菜单时,我在控制台中看到了 Spring Boots 独特的 Logo 。如果我使用 .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();
}

}

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"
}
}

抱歉这个菜鸟问题 - 我如何引导它从 Gradle 很好地运行,这样我就可以从 CI 上下文 (Jenkins) 开始运行?

最佳答案

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

运行 gradlew clean test --info 你会看到更多的输出,包括 Spring 标志

关于java - 使用 Gradle 从 CLI 运行 Spring Boot 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67517017/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com