我正在制作一个Java项目的骨架; gradle构建文件存在一个烦人的问题:测试运行了两次,一次由任务“ JUnitPlatformTest”运行,第二次由任务“ test”运行。
第一个似乎触发了第二个,所以我不能将其禁用,我想保留第二个,因为它们之间有一些区别:第一个在控制台中(intelliJ),第二个使用集成的智能窗口。
这是gradle.build
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.3'
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
classpath 'eu.appsatori:gradle-fatjar-plugin:0.3'
}
}
plugins {
id 'java'
id 'edu.sc.seis.launch4j' version '2.4.4'
}
apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'javafx-gradle-plugin'
apply plugin: 'eu.appsatori.fatjar'
junitPlatform {
platformVersion '1.0.3'
reportsDir file('build/test-results/junit-platform')
enableStandardTestTask true
//show results summary even on success.
details details.SUMMARY
filters {
tags {
// Framework tests need to be run only when required to verify that this framework is still working.
exclude "Framework"
}
includeClassNamePatterns '.*Test', '.*Tests'
}
}
group 'lorry'
version '1'
sourceCompatibility = 1.8
//mainClassName="imports.ColorfulCircles"
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
def final junitVersion = "5.2.0"
compile group: 'com.google.inject', name: 'guice', version: '4.1.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
compile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitVersion
//compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.11.0'
compile group: 'org.assertj', name: 'assertj-core', version: '3.9.0'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junitVersion
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.7.22'
testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitVersion
compile 'org.hamcrest:hamcrest-all:1.3'
testCompile "org.testfx:testfx-core:4.0.13-alpha"
testCompile 'org.testfx:testfx-junit5:4.0.13-alpha'
testRuntime 'org.testfx:openjfx-monocle:8u60-b27'
}
test {
useJUnitPlatform()
jvmArgs = [
"-Dtestfx.robot=glass",
"-Dtestfx.headless=true",
"-Dprism.order=sw",
"-Dprism.text=t2k",
"-Dheadless.geometry=1920x1200-32"
]
}
test.dependsOn 'clean'
jfx {
// minimal requirement for jfxJar-task
mainClass = 'imports.ColorfulCircles'
// minimal requirement for jfxNative-task
vendor = 'lolveley'
}
jar {
baseName = 'executable3'
version = ''
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'imports.ColorfulCircles'
)
}
}
launch4j {
outfile='bibliotek-v3.exe'
mainClassName = 'imports.ColorfulCircles'
icon = "${projectDir}\\icons\\hands2.ico"
copyConfigurable = project.tasks.fatJar.outputs.files
jar = "lib/${project.tasks.fatJar.archiveName}"
//headerType = "console"
//jar = "${buildDir}\\productFatJar\\fat.jar"
}
junitPlatformTest {
jvmArgs = [
"-Dtestfx.robot=glass",
"-Dtestfx.headless=true",
"-Dprism.order=sw",
"-Dprism.text=t2k",
"-Dheadless.geometry=1920x1200-32"
]
}
这是结果:
Testing started at 19:25 ...
19:25:01: Executing task 'test'...
> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
> Task :clean
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses
> Task :junitPlatformTest
constructeur appelé
Before all
Before each
my test 1
Before each
my test 2
This test method should be run
Test run finished after 3630 ms
[ 4 containers found ]
[ 0 containers skipped ]
[ 4 containers started ]
[ 0 containers aborted ]
[ 4 containers successful ]
[ 0 containers failed ]
[ 7 tests found ]
[ 0 tests skipped ]
[ 7 tests started ]
[ 0 tests aborted ]
[ 7 tests successful ]
[ 0 tests failed ]
> Task :test
constructeur appelé
Before all
Before each
my test 1
Before each
my test 2
This test method should be run
BUILD SUCCESSFUL in 13s
5 actionable tasks: 5 executed
19:25:15: Task execution finished 'test'.
答案 0 :(得分:1)
根据this official website,...
JUnit Platform Gradle插件已弃用
JUnit团队开发的最基本的
junit-platform-gradle-plugin
在JUnit Platform 1.2中已弃用,并将在1.3中停产。请切换到Gradle的标准测试任务。
因此,您应该从构建文件中删除此插件,并在必要时尝试将其余设置移植到test
插件的java
任务中。