如何通过gradle测试任务执行测试方法?

时间:2016-10-07 04:32:08

标签: spring spring-boot testng build.gradle

  

当我运行我的testing.xml时,testNG适合运行但运行时   gradle测试任务它不执行测试

     

testing.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite guice-stage="DEVELOPMENT" name="Default suite">
  <test verbose="2" name="test">
    <classes>
      <class name="com.example.EmpBusinessLogicTest"/>
    </classes>
  </test> <!-- Default test -->
</suite> <!-- Default suite -->
  

的build.gradle

     

buildscript {         \ text {             springBootVersion ='1.4.1.RELEASE'         }         存储库{             mavenCentral()         }         依赖{             类路径( “org.springframework.boot:弹簧引导gradle这个-插件:$ {} springBootVersion”)         }       }

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'

jar {
  baseName = 'demo'
  version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8


repositories {
  mavenCentral()
}


dependencies {
  compile('org.springframework.boot:spring-boot-starter-web')
  testCompile('org.springframework.boot:spring-boot-starter-test')
  compile('org.testng:testng:6.9.10')

}

test {
    useTestNG() 
    {        
        suites 'src/main/resources/testing.xml'

    }
}
     

任何人都可以帮我执行gradle测试任务吗?

1 个答案:

答案 0 :(得分:1)

作为选项,您可以在测试任务中直接在gradle中生成xml,它在我们的项目中正常工作

useTestNG() {
    suiteXmlBuilder().suite(name: 'Default suite') {
        test(name : 'test') {
            classes('') {
                'class'(name: 'com.example.EmpBusinessLogicTest')
            }
        }
    }
}

执行此测试任务,例如使用Jenkins,您需要将系统属性传递给它:

systemProperties System.getProperties()
systemProperty 'user.dir', project.projectDir