无法使用gradle build命令运行testng xml

时间:2015-09-07 07:02:05

标签: selenium gradle testng build.gradle

我创建了一个gradle项目并在eClipse中配置了testng。我创建了一个示例testng脚本,当我通过eClipse运行testng.xml时,它已成功执行。 但是,当我从命令提示符执行gradle build / test etc命令时,我的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
                    }
                }
            }

        }
    }
}

先谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

我可以通过在build.gradle中添加以下代码来实现这一目的。

test {
    useTestNG() {
        // runlist to executed. path is relative to current folder
        suites 'src/test/resources/runlist/Sanity.xml'
    }
 } 

谢谢!