首页 文章

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

提问于
浏览
0

当我运行我的testing.xml时,testNG适合运行,但是当运行gradle test task时,它不会执行test 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 存储库{mavenCentral()}依赖关系{classpath(“org.springframework.boot:spring-boot-gradle-plugin:$ ”)}应用插件:'java'
申请插件:'eclipse'
apply plugin:'spring-boot'

jar
sourceCompatibility = 1.8
targetCompatibility = 1.8

存储库{
mavenCentral()
}

依赖{
编译(“org.springframework.boot: spring 引导启动的web”)
testCompile(“org.springframework.boot: spring 引导起动试验”)
编译( 'org.testng:TestNG的:6.9.10')

}

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

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

1 回答

  • 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
    

相关问题