【问题标题】:Not able to run testng xml with gradle build command无法使用 gradle build 命令运行 testng xml
【发布时间】:2015-09-07 07:02:04
【问题描述】:

我创建了一个 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
                    }
                }
            }

        }
    }
}

在此先感谢您的帮助。

【问题讨论】:

  • 嗨团队,对此有任何想法。谢谢

标签: selenium gradle testng build.gradle


【解决方案1】:

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

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

谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-25
    • 2016-12-28
    • 2014-11-02
    相关资源
    最近更新 更多