TestNG 在build.gradle的配置 基于gradle的项目关于TestNG的配置: - dependencies {
- compile('org.testng:testng:6.9.5')
- }
复制代码创建test Task - test {
- ignoreFailures = true
- useTestNG()
- reports.html.enabled = true
- }
复制代码
Jacoco的配置基于gradle项目的jacoco: - apply plugin: 'jacoco'
-
- jacoco {
- toolVersion = '0.8.1'
- reportsDir = file("$buildDir/jacocoReport")
- }
复制代码创建jacoco report task: - jacocoTestReport {
- reports {
- xml.enabled false
- csv.enabled false
- html.enabled true
-
- xml.destination file("${buildDir}/reports/jacoco/jacocoReport/jacocoXml.xml")
- csv.destination file("${buildDir}/reports/jacoco/jacocoReport/jacocoCsv.csv")
- html.destination file("${buildDir}/reports/jacoco/jacocoReport/jacocoHtml")
- }
- }
复制代码
如何执行?在项目里面执行下面的命令 - ./gradlew clean test jacocoTestReport
复制代码Note: 如果在Spring Boot的框架下运行,需要在build.gradle中加下面一段,否则TestNG的test case虽然会被编译,但是执行会被skipped,报No Source错误: - tasks.withType(Test) {
- scanForTestClasses = false
- include "**/*Test.class" // whatever Ant pattern matches your test class files
- }
复制代码
|