Gradleでは、追加のソースセットでテストを見つけることができません

同期:

私の目標は、統合テスト用に設定されたソースを設定することです。私は「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
BUILDは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からこの
-からソリューションこれ

どのように私は、ソースセット「intTest」内部テストを発見するためのGradleを有効にすることができますか?

JB Nizet:

あなたのテストは、JUnitのテスト5ですが、Gradleのに語っていません。ただ、テスト・タスクのようにあなたを呼び出す必要があります

useJUnitPlatform()

あなたの構成でintegrationTest作業。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=334955&siteId=1