当前位置: 首页 > 知识库问答 >
问题:

使用Gradle从CLI运行Spring Boot测试

松飞翮
2023-03-14

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

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

    @Autowired
    private MainPage mainPage;

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

    @Autowired
    private WebDriver driver;


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

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

共有1个答案

宋俊民
2023-03-14

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

使用gradlew clean test-info运行,您将看到更多的输出,包括Spring徽标

 类似资料:
  • 我有几个繁重的Spring集成测试(是的,这不是最好的方法,我没有时间正确地模拟所有外部dep) 下面是测试的典型注释 由于以下原因,测试会定期失败: 这里有两个问题:1、让测试共存的正确方式是什么?我在surefire插件中设置了forkCount=0。好像有帮助 2.1. 在每次测试期间,我实际上不需要启动所有的

  • 问题内容: 我正在尝试使用gradle通过以下命令运行测试,但无法正常工作 我的测试套件如下所示 尝试运行以下命令的方法有效,但更糟糕的是,它每次运行两次测试。一次,然后再次在相同名称空间的测试套件下 我可以删除测试套件并以这种方式进行操作,但是我想更好地了解这里发生了什么以及为什么我不能告诉它直接运行测试套件。 问题答案: 以下为我在本地工作。 与所使用的更高级的过滤方法相比,这实际上使用了不同

  • 是否可以在gradle.properties文件中定义test.maxParallelForks=runtime.runtime.availableProcessors(),而不是在test任务下的每个build.gradle文件中定义它?

  • 我有一个带有gradle Build Jhipster4.6.2应用程序。从IDE运行测试存在问题。测试通常从命令行执行,但通过单击fails for application context Failure(应用程序上下文失败),从STS运行测试失败: 我遵循了https://jhipster.github.io/configuring-ide-eclipse-gradle/的说明,并且可以从ST

  • 问题内容: 目前,我有以下 build.gradle 文件: 这 的build.gradle 文件是我的仓库 在这里 。我所有的主文件都在 src / model /中 ,它们各自的测试在 test / model中 。 如何正确添加JUnit 4 依赖项 ,然后在 测试/模型 文件夹中运行那些测试? 问题答案: 如何正确添加junit 4依赖关系? 假设您要针对标准Maven(或等效版本)存储库