我有一个简单的单元测试,它可以启动我的应用程序并测试某些服务已实例化。只是一个健全的检查。
但是,这些测试未在我的完整测试套件中运行,并且单独运行时,出现错误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
Edit2: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
}