本文介绍了我如何告诉Gradle使用我的testng.xml文件进行测试类和订购?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Gradle执行一些使用testng.xml文件定义的测试。我的testng.xml文件如下所示:

 <!DOCTYPE suite SYSTEMhttp://testng.org/testng- 1.0.dtd> 

<听众>
< listener class-name =mypackage.MyListener/>
< listener class-name =mypackage.TestOrderer/>
< / listeners>

< test name =Tests>
< classes>
< class name =mytestpackage.CrazyTest1/>
< class name =mytestpackage.CrazyTest2/>
< class name =mytestpackage.CrazyTest3/>
< / classes>
< / test>
< / suite>

那为什么我需要这个?我想确保我的测试的组织方式是由类似于列出的注释定义的。正如你可能猜到的,TestOrderer是一个IMethodInterceptor。



这是问题所在,Gradle似乎正在接管我的testng.xml文件并且抓取测试目录以找到它想要执行的测试。即使我禁用了它,也无法正确执行这些方法。这是我认为应该工作,但只是,没有。

  test {
useTestNG()
options.suites(src / test / resources / crazyTestNG.xml)
#添加
#scanForTestClasses = false
#导致零测试被执行,因为类名不结束于测试
}

这似乎应该是一件容易的事... fork TestNG进程并让它运行,但我无法弄清楚如何告诉Gradle走出困境并执行我的测试。 解决方案



  

应用插件:'java'

存储库{
mavenCentral()
}
依赖关系{
//根据需要添加依赖关系
testCompile ('lib')
}
测试(
useTestNG())'testg',版本:'6.8.8'
测试编译文件树{
// runlist执行。路径相对于当前文件夹
套件的src / test / resources / runlist / my_test.xml'
}
}


I am attempting to have Gradle execute some tests defined using a testng.xml file. My testng.xml file looks like this:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="mySuite" verbose="1">

  <listeners>
    <listener class-name="mypackage.MyListener" />
    <listener class-name="mypackage.TestOrderer" />
  </listeners>

  <test name="Tests">
    <classes>
      <class name="mytestpackage.CrazyTest1"/>
      <class name="mytestpackage.CrazyTest2"/>
      <class name="mytestpackage.CrazyTest3"/>
    </classes>
  </test>
</suite>

So why do I need this? I want to ensure that my tests are organized in a way that's defined by annotations similar to that which was listed here. As you might guess, TestOrderer is an IMethodInterceptor.

Here's the problem, Gradle seems to be taking over my testng.xml file and scraping the test directory to find the tests it wants to execute. Even if I disable this, it fails to execute the methods appropriately. Here's what I think should work, but just, doesn't.

test {
  useTestNG()
  options.suites("src/test/resources/crazyTestNG.xml") 
  # Adding 
  # scanForTestClasses = false 
  # causes zero tests to be executed, since the class names don't end in Test
}

It seems like it should be a no-brainer...fork the TestNG process and let it run, but I can't figure out how to tell Gradle to get out of the way and just execute my tests.

解决方案

Here's how you can configure a test suite (xml) to be executed in a Gradle task:

apply plugin: 'java'

repositories {
    mavenCentral()
}
dependencies {
    // add the dependencies as needed
    testCompile group: 'org.testng', name: 'testng', version:'6.8.8'
    testCompile fileTree('lib')
}
test {
    useTestNG() {
        // runlist to executed. path is relative to current folder
        suites 'src/test/resources/runlist/my_test.xml'
    }
}

这篇关于我如何告诉Gradle使用我的testng.xml文件进行测试类和订购?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 18:11