gpt4 book ai didi

java - gradle集成测试不起作用,单元测试运行两次

转载 作者:行者123 更新时间:2023-12-03 05:44:33 26 4
gpt4 key购买 nike

我有这个根 build.gradle

repositories {
jcenter()
}

subprojects {

apply plugin: 'java'

group 'me.someone'
version '1.0.0'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
jcenter()
mavenCentral()
}

dependencies {
testImplementation 'junit:junit:4.12'
}

}

然后我有这个 child build.gradle
plugins {
id 'java-library'
id 'eclipse'
id "org.springframework.boot" version "2.0.1.RELEASE"
id 'io.spring.dependency-management' version "1.0.5.RELEASE"
}

dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile project(':foo-jar')

testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.18.3'

}

sourceSets {
main {
java {
srcDir 'src/main/java'
}
}

test {
java.srcDir file('src/int/java')
}

itest {
java {
srcDir file('src/itest/java')
}
//resources.srcDir 'src/itest/resources'
}
}


test {
testLogging {
showStandardStreams = true
events "passed", "skipped", "failed"
exceptionFormat = 'full'
}
}

task itest(type: Test) {
testLogging {
showStandardStreams = true
events "passed", "skipped", "failed"
exceptionFormat = 'full'
}
itest.mustRunAfter test
}

check.dependsOn itest

bootRun {
main = 'me.someone.BarServiceApplication'
}

问题是单元测试运行两次,但集成测试没有运行。为什么单元测试要运行两次,但不能运行集成测试?我的理解是,当我提供集成测试的源文件夹时,它也应该运行集成测试。

最佳答案

您的任务itest需要具有其 testClassesDirs configured,这就是为什么它当前正在两次运行单元测试的原因。它可能还需要 classpath configured

您应该查看how to do integration tests上的Gradle文档以获取所有详细信息。

关于java - gradle集成测试不起作用,单元测试运行两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50752941/

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