@SpringBootTest 导致“未找到给定包含的测试”

2024-02-05

我有简单的单元测试,它启动我的应用程序并测试某些服务是否已实例化。有点像健全性检查。

但是,这些测试并未在我的完整测试套件中运行,当单独运行时,我收到错误No tests found for given includes: [com.example.AppTest](filter.includeTestsMatching)

这是我的单元测试

import com.sblukcic.cli.flags.CLIParser;
import org.junit.Rule;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.rules.TemporaryFolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.Assert.fail;

@ExtendWith(SpringExtension.class)
@SpringBootTest
public class AppTest {

    @Autowired
    private ApplicationContext context;

    @Autowired
    private CLIParser parser;

    @Rule
    public static TemporaryFolder folder = new TemporaryFolder();

    private static File nonEmptyFile;

    @BeforeAll
    public static void setUp() throws Exception {
        folder.create();
        nonEmptyFile = folder.newFile("myNextFile.txt");

        try(BufferedWriter br = new BufferedWriter(new FileWriter(nonEmptyFile))){
            br.write("I AM NOT EMPTY!");
            br.flush();
        }catch (IOException ioe){
            fail();
        }
    }

    @Test
    public void givenAppStarted_whenLoaded_checkContextLoaded() {
        assertThat(context).isNotNull();
    }

    @Test
    public void whenAppStarted_checkParserLoadedCorrectly() {
        assertThat(parser).isNotNull();
    }

}

任何想法,提前致谢。

编辑:我刚刚使用 --debug 选项运行测试,它在测试失败之前显示这一点

11:06:58.322 [QUIET] [system.out] </event></ijLog>
11:06:58.322 [DEBUG] [TestEventLogger]     [11:06:58] [32m[INFO][m Starting AppTest on equipment with PID 22040 (started by sam in /home/sam/IdeaProjects/SBL Xsam Kit)
11:06:58.325 [QUIET] [system.out] 
11:06:58.325 [QUIET] [system.out] </event></ijLog>
11:06:58.325 [DEBUG] [TestEventLogger]     [11:06:58] [32m[INFO][m No active profile set, falling back to default profiles: default
11:06:58.944 [LIFECYCLE] [org.gradle.process.internal.health.memory.MemoryManager] 
11:06:58.944 [DEBUG] [org.gradle.process.internal.health.memory.MemoryManager] Emitting OS memory status event {Total: 67473440768, Free: 55896666112}
11:06:58.944 [DEBUG] [org.gradle.launcher.daemon.server.health.LowMemoryDaemonExpirationStrategy] Received memory status update: {Total: 67473440768, Free: 55896666112}
11:06:58.944 [DEBUG] [org.gradle.process.internal.health.memory.MemoryManager] Emitting JVM memory status event {Maximum: 1016594432, Committed: 1009778688}
11:06:59.605 [DEBUG] [org.gradle.launcher.daemon.server.Daemon] DaemonExpirationPeriodicCheck running
11:06:59.605 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
11:06:59.605 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
11:06:59.605 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
11:06:59.605 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
11:06:59.606 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
11:06:59.606 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
11:06:59.930 [DEBUG] [org.gradle.internal.remote.internal.inet.SocketConnection] Discarding EOFException: java.io.EOFException
11:06:59.938 [DEBUG] [org.gradle.launcher.daemon.server.SynchronizedDispatchConnection] thread 6911: dispatching class org.gradle.launcher.daemon.protocol.BuildEvent
11:06:59.939 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Opening cache fileHashes.bin (/home/sam/IdeaProjects/SBL Xsam Kit/.gradle/4.8/fileHashes/fileHashes.bin)
11:06:59.940 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Opening cache taskHistory.bin (/home/sam/IdeaProjects/SBL Xsam Kit/.gradle/4.8/taskHistory/taskHistory.bin)
11:06:58.299 [LIFECYCLE] [org.gradle.internal.operations.DefaultBuildOperationExecutor] 
11:06:58.299 [LIFECYCLE] [org.gradle.internal.operations.DefaultBuildOperationExecutor] > Task :test FAILED
11:06:59.464 [QUIET] [system.out] 
11:06:59.465 [QUIET] [system.out] </event></ijLog>
11:06:59.465 [DEBUG] [TestEventLogger]     [11:06:59] [32m[INFO][m Started AppTest in 1.547 seconds (JVM running for 4.207)
11:06:59.931 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: SUCCEEDED

编辑2:Gradle设置

plugins {
    id 'java'
    id 'jacoco'
}

//gradle wrapper --gradle-version 4.10.3

group 'com.sblukcic'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

dependencies {
    // https://mvnrepository.com/artifact/org.mockito/mockito-core
    testCompile group: 'org.mockito', name: 'mockito-core', version: '2.18.3'

    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test
    testCompile (group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.4.RELEASE'){
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }

    // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.3.2'

    // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.3.2'

    testRuntime(
            'org.junit.jupiter:junit-jupiter-engine:5.1.0',
            'org.junit.vintage:junit-vintage-engine:5.1.0',
            'org.junit.platform:junit-platform-launcher:1.1.0',
            'org.junit.platform:junit-platform-runner:1.1.0'
    )

    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter
    compile (group: 'org.springframework.boot', name: 'spring-boot-starter', version: '2.1.4.RELEASE') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }

    // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-log4j2
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2', version: '2.1.4.RELEASE'

    // https://mvnrepository.com/artifact/org.projectlombok/lombok
    compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.6'

    // https://mvnrepository.com/artifact/commons-chain/commons-chain
    compile group: 'commons-chain', name: 'commons-chain', version: '1.2'

    // https://mvnrepository.com/artifact/com.beust/jcommander
    compile group: 'com.beust', name: 'jcommander', version: '1.72'


    // https://mvnrepository.com/artifact/org.jacoco/org.jacoco.core
    compile group: 'org.jacoco', name: 'org.jacoco.core', version: '0.8.3'

    //in house code.
    compile 'com.gitlab.SBLUKcic:xsam-core:1.42'
    compile 'com.gitlab.SBLUKcic:apu-convert:1.1'
}

jacoco {
    toolVersion = "0.8.2"
    reportsDir = file("$buildDir/customJacocoReportDir")

}

jacocoTestReport {
    reports {
        xml.enabled false
        csv.enabled false
        html.destination file("${buildDir}/jacocoHtml")
    }
}

jacocoTestCoverageVerification{
    violationRules{
        rule{
            limit{
                minimum = 0.7
            }
        }
    }
}


test{

    useJUnitPlatform {
        includeEngines 'junit-jupiter', 'junit-vintage'
    }

    maxHeapSize = '2G'

    failFast = true

    finalizedBy jacocoTestReport

}

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

@SpringBootTest 导致“未找到给定包含的测试” 的相关文章

随机推荐

  • Spring 3 项目上的 java.lang.ClassNotFoundException:org.codehaus.jackson.map.ObjectMapper

    我正在尝试在没有 Maven 的情况下建立一个 Spring 项目 我的项目必须通过 Spring MVC 框架提供 jsp 页面和 json 流 Jsp 页面的部分运行良好 但是当我尝试设置 json 流 为了进行 ajax GET 时
  • Java 中 JSON 注入的 Fortify 错误

    我正进入 状态SUBSCRIPTION JSON来自客户端 我将其转换为字符串 然后使用 gson 库将其设置为模型对象 在 Fortify security 上运行代码时 下面的代码出现 Json 注入错误 并显示以下消息 这是错误 On
  • 请求太大

    我的页面上收到以下错误 我更新了 IIS 设置以进行发布限制 但找不到如何增加工作缓冲区大小 对此的任何帮助都很棒 Request Too Large The POST request is too large for the intern
  • 优化 2D 旋转

    给出在 2D 空间中旋转点的经典公式 cv Point pt NPOINTS cv Point rotated NPOINTS float angle WHATEVER float cosine cos angle float sine s
  • 在xml中使用android:tag参数?

    我看到一个 xml 布局 其中有一个 textView 如下所示
  • Android:如何在收到 Firebase 动态链接后删除对它的引用? [复制]

    这个问题在这里已经有答案了 在我的应用程序中 我在主要活动中收到动态链接 当用户打开链接并启动应用程序并完成正确的操作时 这非常有效 但动态链接在应用程序中检索后似乎仍然存在 即使用户按下链接并在应用程序中检索它FirebaseDynami
  • mobile.de 搜索 api 授权 fehler mit PHP curl

    我试图从 mobile de 搜索 API http services mobile de manual search api html 但它不起作用 每次都会出现此错误 HTTP 状态 401 此请求需要 HTTP 身份验证 我究竟做错了
  • 正确显示 DICOM 图像 ITK-VTK(图像太暗)

    我使用 itk ImageSeriesReader 和 itk GDCMImageIO 读取 dicom 图像 然后使用 itk FlipImageFilter 翻转图像 以获得图像的正确方向 并使用 itk ImageToVTKImage
  • Angular 1.5 组件方法 templateUrl + function

    我正在尝试让应用程序与 Angular 1 5 0 beta 2 一起使用 为了制定 指令 我有以下代码 myApp component gridshow bindings slides controller function contro
  • Ghostscript是否可以为PDF的每个页面添加水印

    我转换PDF gt 许多 JPEG and 许多 JPEG gt 许多 PDF using ghostscript 我需要在每个转换后的 JPEG PDF 页面上添加水印文本 是否可以仅使用 Ghostscript 和 PostScript
  • 我可以使用 Google Cloud Monitoring 来监控发生故障的 Container/Pod 吗?

    尝试Google Cloud Monitoring 当容器或 Pod 出现错误 无法调度等情况时 我正在努力使用开箱即用的指标创建警报 监控我的应用程序是否健康的非常基本的东西 使用 Prometheus 进行配置非常容易 有一种称为 GK
  • 具有 ocLazyLoad 的动态 ui-router 在解析中使用多个模块

    解决了见下文 从这个问题 解决方案开始工作堆栈溢出问题 https stackoverflow com questions 26630586 angularjs dynamic stateprovider with ui router vi
  • Dart 中有编译器预处理器吗?

    由于在启动 dart 应用程序之前需要进行编译 我想知道编译器预处理器是否可用 或者是否计划在不久的将来为 Dart 提供 到目前为止 我在网络上 在 dart 网站内部的搜索均未成功 通过预处理器 我的意思是 define max A B
  • Django:有没有办法知道应用程序中的网址是否有效?

    这是我的目标 用户想要登录 我在每个页面上创建一个按钮 并以 urlback 作为参数 例如 如果我们在该页面上http olivier life today 登录按钮将有一个像这样的 urlhttp olivier life login
  • 为什么我不能给指针赋值?

    在阅读了常见问题解答和我能找到的所有其他内容后 我仍然感到困惑 如果我有一个以这种方式初始化的 char 指针 char s Hello world 该字符串位于只读存储器中 我无法像这样更改它 s W 制作 Hello world 我明白
  • spring mvc中如何管理/存储后续请求的请求参数?

    我经常使用场景 列出用户 在ajax调用上 在搜索页面上 搜索按钮后单击一些搜索条件 我有 jQuery 数据表中的用户列表 点击编辑用户在数据表中 我单击以从列表中编辑用户 我重定向到用户更新表单 其中填充了用于更新目的的用户字段 更新用
  • “selectedFilters”不是有效的关键字参数

    我使用 PyQt5 当我尝试保存文件名时出现错误 csv file list QtWidgets QFileDialog getOpenFileName self Open file csv fileName csv file list f
  • 防止 AngularJs 使用 jQuery 库

    Question 如何防止 AngularJs 使用 jQuery 背景 我正在 AngularJs 中开发一个独立的应用程序 可以 插入 到现有的客户端网站中 这些客户端网站可能已经使用 jQuery 如果您使用过 AngularJs 您
  • 程序在发生任何事情之前就在调试器中崩溃了

    我正在使用 MinGW 工具链构建一个适用于 Windows XP 的应用程序 它有时会意外崩溃 因此 我尝试使用调试器 Gdb 但程序在发生任何事情之前都会以代码 03 退出 事实上 我从GDB看到的只是 新线程3184 0x7b8 新线
  • @SpringBootTest 导致“未找到给定包含的测试”

    我有简单的单元测试 它启动我的应用程序并测试某些服务是否已实例化 有点像健全性检查 但是 这些测试并未在我的完整测试套件中运行 当单独运行时 我收到错误No tests found for given includes com exampl