简体   繁体   中英

When using TestNG with IDEA and Gradle, the TestNG library and the test sources are not recognised, resulting in the tests not being run

I have the following build.gradle :

buildscript {
    ext {
        picocli = '4.3.2'
        janino = '3.1.2'
        questdb = '5.0.1'
        babl = '0.4.1'
        pac4j = '4.0.2'
        eclipse_collections = '10.2.0'
        logback = '1.2.3'
        junit = '4.12'
        testng = '7.1.0'
        kotlin_version = '1.3.72'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        google()
        jcenter()
    }

    dependencies {
    }
}

plugins {
    id 'java'
    id 'org.jetbrains.kotlin.multiplatform' version "$kotlin_version"
}

apply from: 'activej.gradle'
apply from: 'pac4j.gradle'
apply from: 'kotlin.gradle'

description '...'

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

kotlin {
    jvm {
        withJava()
    }
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11

    kotlinOptions {
        jvmTarget = '11'
        apiVersion = '1.3'
        languageVersion = '1.3'
    }
}

test {
    // enable TestNG support (default is JUnit)
    useTestNG()

    // show standard out and standard error of the test JVM(s) on the console
    testLogging.showStandardStreams = true

    // Fail the 'test' task on the first test failure
    failFast = false

    //we want display the following test events
    testLogging {
        events "PASSED", "FAILED", "SKIPPED"
    }
}

dependencies {
    implementation group: 'info.picocli', name: 'picocli', version: "$picocli"

    implementation group: 'org.codehaus.janino', name: 'janino', version: "$janino"

    implementation group: 'org.questdb', name: 'core', version: "$questdb"

    implementation group: 'com.aitusoftware', name: 'babl', version: "$babl", ext: 'pom'

    implementation group: 'org.eclipse.collections', name: 'eclipse-collections-api', version: "$eclipse_collections"
    implementation group: 'org.eclipse.collections', name: 'eclipse-collections', version: "$eclipse_collections"

    implementation group: 'ch.qos.logback', name: 'logback-classic', version: "$logback"

    // testImplementation group: 'junit', name: 'junit', version: "$junit"

    testImplementation group: 'org.testng', name: 'testng', version: "$testng"
}

Files activej.gradle , pac4j.gradle and `kotlin.gradle has just other depedecies.

My directory structure is:

src
 |- main
      |- java
      |- kotlin
      |- resources
 |- test
      |- java
      |- kotlin
      |- resources

I am using TestNG.

I have a mock test file for the time being:

package com.sirinath.activej.config

import org.testng.annotations.*;

@Test
class TestRouteBuilder {
    @Test
    public fun test() {
        System.out.println("Testing")
    }
}

When I execute testClasses I get:

11:08:29 pm: Executing task 'testClasses'...


> Configure project :server
Kotlin Multiplatform Projects are an experimental feature.

> Task :wrapper

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

> Configure project :server
Kotlin Multiplatform Projects are an experimental feature.

> Task :server:compileKotlinJvm NO-SOURCE
> Task :server:compileJava NO-SOURCE
> Task :server:jvmProcessResources NO-SOURCE
> Task :server:processResources SKIPPED
> Task :server:classes UP-TO-DATE
> Task :server:jvmMainClasses UP-TO-DATE
> Task :server:compileTestKotlinJvm NO-SOURCE
> Task :server:compileTestJava NO-SOURCE
> Task :server:jvmTestProcessResources NO-SOURCE
> Task :server:processTestResources SKIPPED
> Task :server:testClasses UP-TO-DATE

BUILD SUCCESSFUL in 947ms
11:08:32 pm: Task execution finished 'testClasses'.

I have 3 issues here:

  1. The tests are not run.
  2. It says NO-SOURCE when I have code in src\main\java , src\main\kotlin and src\test\kotlin directories. If it is not finding the source I want to know where it is looking as there are source files.
  3. IntelliJ IDEA IntelliSense does not recognise org.testng.* packages, as well as, other dependencies, though it is shown in the project structure in IDEA. I have tried clearing the IDE cache which has no effect.
  1. Changing id 'org.jetbrains.kotlin.multiplatform' version "$kotlin_version" to id 'org.jetbrains.kotlin.jvm' version "$kotlin_version" and
  2. removing
kotlin {
    jvm {
        withJava()
    }
}

solves all 3 problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM