2015-09-07 77 views
0

我已經創建了一個gradle項目並在eClipse中配置了testng。我創建了一個示例testng腳本,並在我通過eClipse運行testng.xml時成功執行了該腳本。 但是,當我從命令提示符執行gradle build/test等命令時,我的testng.xml沒有得到執行。無法使用gradle構建命令運行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 
        } 
       } 
      } 

     } 
    } 
} 

在此先感謝您的幫助。

+0

嗨團隊,對此有任何想法。謝謝 – Durgesh

回答

0

我能夠通過在build.gradle中添加以下代碼來實現此目的。

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

謝謝!