私の目標は、統合テスト用のソース セットをセットアップすることです。「intTest」というソースセットを作成しました。内部に簡単なテストを入れます:
package com.github.frozensync;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class Application {
@Test
@DisplayName("should work")
void foo() {
assertEquals(2, 2);
}
}
実行しようとすると、次のエラーが表示されます。
FAILURE: ビルドは例外で失敗しました。
* 問題:
タスク ':integrationTest' の実行に失敗しました。
> 指定されたインクルードのテストが見つかりません: [com.github.frozensync.Application](filter.includeTestsMatching)
* 試してください:
--stacktrace オプションを指定して実行し、スタック トレースを取得します。--info または --debug オプションを指定して実行し、より多くのログ出力を取得します。--scan を指定して実行すると、完全な洞察が得られます。
* https://help.gradle.org
でさらにヘルプを得る 0ms でビルドが失敗しました
そして、これは私のbuild.gradle
plugins {
id 'java'
}
group 'com.github.frozensync'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
sourceSets {
intTest {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
}
idea {
module {
testSourceDirs += sourceSets.intTest.java.srcDirs
testResourceDirs += sourceSets.intTest.resources.srcDirs
}
}
configurations {
intTestImplementation.extendsFrom implementation
intTestRuntimeOnly.extendsFrom runtimeOnly
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.5.2'
intTestImplementation 'org.junit.jupiter:junit-jupiter:5.5.2'
}
test {
useJUnitPlatform()
}
task integrationTest(type: Test) {
description = 'Runs integration tests.'
group = 'verification'
testClassesDirs = sourceSets.intTest.output.classesDirs
classpath = sourceSets.intTest.runtimeClasspath
shouldRunAfter test
}
check.dependsOn integrationTest
Gradleのガイドに従いました。問題に直面したとき、私は次のことを試しました:
- ./gradlew cleanIntegrationTest integrationTest
IntelliJ をバイパスするために実行しますが、それでも 0 個のテストを実行しました -アイデア Gradle プラグイン
を追加します。・こちらから
追加。
- これからの解決策。dependsOn
Gradle がソースセット「intTest」内のテストを検出できるようにするにはどうすればよいですか?