【问题标题】:Issue with @BeforeSuite and @AfterSuite with TestNG plugin in EclipseEclipse 中带有 TestNG 插件的 @BeforeSuite 和 @AfterSuite 问题
【发布时间】:2012-10-25 20:14:04
【问题描述】:

我有几个套房,如 Suite1、Suite2、Suite3 等。我还有一个名为 CommonSuite 的通用套件,它有 @BeforeSuite@AfterSuite 方法。我有一个配置了所有套件的 testng.xml,并且我正在使用 maven 故障安全插件来运行测试。一切正常。

现在我的问题是如果我想在 Eclipse 中使用 TestNG 插件运行/调试说 只是 Suite1,我如何确保我的 CommonSuite 也包含在 Suite1 中?我知道的一种肮脏方式是,我可以评论我不想在 testng.xml 中运行的所有套件,只保留 CommonSuite 和 Suite1,然后作为 TestNG 套件运行/调试。不过,这似乎不是正确的方法。还有其他更好的方法来实现这一点吗?

【问题讨论】:

    标签: java testng


    【解决方案1】:

    你最好的方法是实现一个listner类,以便实现ISuiteListener

    基本类如下所示

        public class PlatformSuite implements ISuiteListener { 
    
        /**
         * This method is invoked before the SuiteRunner starts.
         */
        public synchronized void onStart(ISuite suite) {
            /*Your before suite implementation here*/
        }
    
        /**
         * This method is invoked after the SuiteRunner has run all
         * the test suites.
         */
    
        public void onFinish(ISuite suite) {
             /*Your after suite implementation here*/
        }
    
    }}
    

    对于 Eclipse 插件,您可以将 testng xmal 指定为“模板 XML 文件”

    要在 testng.xml 中启动侦听器,您可以添加以下内容,请记住设置不可用的默认侦听器设置

    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
    <suite name="DssTestSuite" parallel="false">
        <parameter name="useDefaultListeners" value="false"/>
        <listeners>
            <listener class-name="org.someonr.something.core.PlatformSuite"/>
        </listeners>
    <test name="sample Test" parallel="false" verbose="2">
        <packages>
        </packages>
        <classes>         
        </classes>
    </test>
    

    此调用将在每个测试套件之前和每个测试套件之后调用

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-09
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    相关资源
    最近更新 更多