本文介绍了如何通过名称和通配符运行带有TestNG的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆带有TestNG测试的类,我有一个方便的命名约定。我想制作只运行所有以Xyz开头的类的测试套件。有没有办法做到这一点?我希望它的工作方式是使用这样的通配符:

I have a bunch of classes with TestNG tests in them, and I have a handy naming convention. I'd like to make test suites that just run all the classes that start with Xyz. Is there any way of doing that? The way I wish it would work is with a wildcard like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="MySuite" parallel="tests" thread-count="10" preserve-order="false">
<parameter name="sauceOs" value="win7" />
    <test name="testName">
        <classes>
            <class name="packageName.BeginningOfClassName*"></package>
        </classes>
    </test>
</suite>


推荐答案

你可以使用。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="MySuite" parallel="tests" thread-count="10" preserve-order="false">
<parameter name="sauceOs" value="win7" />
    <test name="testName">
         <method-selectors>
             <method-selector>
               <script language="beanshell"><![CDATA[
                 method.getDeclaringClass().getSimpleName().startsWith("ClassNamePrefix")
               ]]></script>
             </method-selector>
        </method-selectors>
        <packages>
            <package name="packageName"></package>
        </packages>
    </test>
</suite>

这篇关于如何通过名称和通配符运行带有TestNG的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 09:59