简体   繁体   中英

“No tests found for given includes” for TestNG + Gradle + @Test(dependsOnMethods)

I have following dummy test class

package my.test;

import org.testng.annotations.*;

public class NgScenario {

    public static void trace(String msg) {
        System.err.println(msg);
    }

    @BeforeClass
    public void init() {
        trace("-- NgScenario");
    }

    @AfterClass
    public void shutdown() {
        trace("-- NgScenario");
    }

    @Test(dependsOnMethods = {"step2"})
    public void step1() throws Exception {
        trace("-- step1");
    }

    @Test
    public void step2() throws Exception {
        trace("-- step2");
    }

    @Test(dependsOnMethods = {"step2"})
    public void step3() throws Exception {
        trace("-- step3");
    }
}

and build.gradle

apply plugin: 'java'

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

dependencies {
    compile "org.testng:testng:6.9.10"
}

test {
    useTestNG()
    scanForTestClasses = false  
    include '**/*'

    beforeTest { descriptor ->
        logger.lifecycle("Gradle running test: ${descriptor}")
    }
}

When I execute simple command gradle test - everything is OK and output is following (note: step2 intentionally depends on step1 to check that order is indeed correct):

Gradle running test: Test method step2(my.test.NgScenario)
Gradle running test: Test method step1(my.test.NgScenario)
Gradle running test: Test method step3(my.test.NgScenario)

Now, assuming I have 100 methods in scenario and I want to test-debug in my IDE only single branch of methods - I run command gradle test --tests my.test.NgScenario.step1 and receive this error

No tests found for given includes: [my.test.NgScenario.step1]

step1 has dependsOnMethods in its annotation. Same command for test without dependsOnMethods runs OK: gradle test --tests my.test.NgScenario.step2 .

So the question is - what I'm doing/expecting wrong?

I'd like to both use test scenarios and be able to start individual test sub-tree in IDE.

On top of this - it would be nice to be able execute 'step1' without tasks it depends on (assuming 'parent' steps are 'clean+setup' - they are not needed for debugging of single test with all pre-requisites already in-place).

As off-topic - another framework which is able to integrate into gradle build can be recommended.

尝试这个:

gradle :clean  -Dtest.single=Name_of_your_test_here test

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