无法使用 gradle 构建命令 运行 testng xml

Not able to run testng xml with gradle build command

我已经创建了一个 gradle 项目并在 eClipse 中配置了 testng。我已经创建了一个示例 testng 脚本,当我通过 eClipse 运行 testng.xml 时,该脚本成功执行。 但是,当我从命令提示符执行 gradle build/test 等命令时,我的 testng.xml 没有被执行。

我没有遇到任何错误,但是无法使用 gradle 命令 运行 testng.xml。

你能帮我解决这个问题吗?下面是我正在使用的build.gradle。

apply plugin: "java"
apply plugin: "maven"

group = "myorg"
version = 1.0
def poiVersion = "3.10.1"

repositories {
   maven {
            url "rep_url"
        }
}

sourceSets.all { set ->
    def jarTask = task("${set.name}Jar", type: Jar) {
        baseName = baseName + "-$set.name"
        from set.output
    }

    artifacts {
        archives jarTask
    }
}

sourceSets {
    api
    impl
}

dependencies {
    apiCompile 'commons-codec:commons-codec:1.5'

    implCompile sourceSets.api.output
    implCompile 'commons-lang:commons-lang:2.6'

    testCompile 'junit:junit:4.9'
    testCompile sourceSets.api.output
    testCompile sourceSets.impl.output
    testCompile group: 'org.testng', name: 'testng', version: '6.9.5'
    runtime configurations.apiRuntime
    runtime configurations.implRuntime
    compile('org.seleniumhq.selenium:selenium-java:2.47.1') {
        exclude group: 'org.seleniumhq.selenium', module: 'selenium-htmlunit-driver'
        exclude group: 'org.seleniumhq.selenium', module: 'selenium-android-driver'
        exclude group: 'org.seleniumhq.selenium', module: 'selenium-iphone-driver'
        exclude group: 'org.seleniumhq.selenium', module: 'selenium-safari-driver'
        exclude group: 'org.webbitserver', module: 'webbit'
        exclude group: 'commons-codec', module: 'commons-codec'
        exclude group: 'cglib', module: 'cglib-nodep'
        }
    compile "org.apache.poi:poi:${poiVersion}"
    compile "org.apache.poi:poi-ooxml:${poiVersion}"
    compile "org.apache.poi:ooxml-schemas:1.1"  
}

tasks.withType(Test) {
    scanForTestClasses = false
    include "**/*.xml" // whatever Ant pattern matches your test class files
}

jar {
    from sourceSets.api.output
    from sourceSets.impl.output
}

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: uri("${buildDir}/repo"))

            addFilter("main") { artifact, file -> artifact.name == project.name }
            ["api", "impl"].each { type ->
                addFilter(type) { artifact, file -> artifact.name.endsWith("-$type") }

                // We now have to map our configurations to the correct maven scope for each pom
                ["compile", "runtime"].each { scope ->
                    configuration = configurations[type + scope.capitalize()]
                    ["main", type].each { pomName ->
                        pom(pomName).scopeMappings.addMapping 1, configuration, scope
                    }
                }
            }

        }
    }
}

在此先感谢您的帮助。

我可以通过在 build.gradle.

中添加以下代码来实现此目的
test {
    useTestNG() {
        // runlist to executed. path is relative to current folder
        suites 'src/test/resources/runlist/Sanity.xml'
    }
 } 

谢谢!