0

I want to set parameter thread-count in existing suite xml file gradle custom task with type Test. I Want to set useTestNG and after that use TestNG.class for test

String sourceDir = "src"
String resourcesPath = sourceDir.concat("/test/resources")

sourceSets {
test {
    java {
        srcDirs = [sourceDir]
        }
    resources {
        srcDirs = [resourcesPath]
        }
    }
}

apply plugin: 'java'

dependencies {
compile project(':core')
compile group: 'org.testng', name: 'testng', version: '6.1.1'
}

task customTask(type: Test) {

    useTestNG {
        String threads = System.getenv("THREADS")
        String suiteName = System.getenv("SUITE")
        useDefaultListeners = true
        testLogging {
            events "passed", "skipped", "failed"
        }
     }

    //What I trying to do, but i have no acces to testng package

    TestNG tng = new TestNG();
    tng.setXmlSuites(suiteName);
    tng.setThreadCount(threads)
    tng.run(); 
}

So how I add parameter thread count using existing xml testng suite? Do I have create TestNG instance, set suite from existing file and set threadCount? And how I can create suite object from exising xml file?

ZakZand
  • 3
  • 6
  • Its not clear what you are trying to do. But if you want to just alter the thread count value, then you merely need to build a listener that implements `org.testng.IAlterSuiteListener` and then work with that. – Krishnan Mahadevan Sep 07 '17 at 02:50
  • I trying to use in useTestNG or after it(in customTask) use TestNG.class – ZakZand Sep 07 '17 at 07:19
  • And what do you intend to do by getting access to the `TestNG` class? – Krishnan Mahadevan Sep 07 '17 at 07:21
  • TestNG.class I want to use for set existing xml suite and set thread count like in official testng documentation. My question is about how to add ability to use testng library or concrete class from my core project(core its name of module in my project).in customTask. Becase my customtask doesn't see TestNG.class, it see only gradle testing package. – ZakZand Sep 07 '17 at 07:40
  • That is exactly what I was hinting in my previous comment. You don't need to have access to the `TestNG` instance. You can do all those things via TestNG listeners. I would suggest that you please upgrade to the latest released version of TestNG and then leverage the listeners. If you can call out the set of things that you are looking to alter, I can suggest the corresponding listeners and the overall approach you need to follow to get it done. So please help update your question with the set of things that you are looking to alter. – Krishnan Mahadevan Sep 07 '17 at 07:42
  • org.testng.IAlterSuiteListener? this is also testng package. how can I get access to this implementation, if I have access only to gradle testing package? The **main question** is how to **add access to testng libraty in custom task** – ZakZand Sep 07 '17 at 08:13
  • Question is updated :) – ZakZand Sep 07 '17 at 23:54
  • Please refer to my answer [here](https://stackoverflow.com/a/46122127/679824) – Krishnan Mahadevan Sep 08 '17 at 17:56

0 Answers0