zoukankan      html  css  js  c++  java
  • testNG之顺序执行

    @Test
     
    testNG1.java:
    import org.testng.annotations.Test;
     
    public class testNG1 {
        @Test
        public void testNg() {
        System.out.println("this is testNG1");
        }
    }
    testNG2.java:
    import org.testng.annotations.Test;
     
    public class testNG2 {
        @Test
        public void testNg() {
        System.out.println("this is testNG2");
        }
    }
     
    testNG3.java:
    import org.testng.annotations.Test;
     
    public class testNG3 {
        @Test
        public void testNg() {
        System.out.println("this is testNG3");
        }
    }
     
    testng.xml:
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
      
    <suite name="Suite1" verbose="1" >
        <test name="Regression1" >
            <classes>
                <class name="testNG2" />
                <class name="testNG1" />
                <class name="testNG3" />
            </classes>
        </test>
    </suite>
    运行testng.xml,执行结果:
    this is testNG1
    this is testNG2
    this is testNG3
     
     
    preserve-order="true"
     
    默认testng.xml是按字典的顺序执行,如果想要按照xml中class的顺序执行,可以在test节点加上preserve-order="true",修改testng.xml如下:
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
      
    <suite name="Suite1" verbose="1" >
        <test name="Regression1" preserve-order="true" >
            <classes>
                <class name="testNG2" />
                <class name="testNG1" />
                <class name="testNG3" />
            </classes>
        </test>
    </suite>
    再次运行testng.xml,执行结果:
    this is testNG2
    this is testNG1
    this is testNG3
     
     
    preserve-order="true"属性同样适用于class中的方法
     
    testNG4.java
    import org.testng.annotations.Test;
    
    public class testNG4 {
        @Test
        public void testNgMethond1() {
            System.out.println("this is testNgMethond1");
        }
        
        @Test
        public void testNgMethond2() {
            System.out.println("this is testNgMethond2");
        }
        
        @Test
        public void testNgMethond3() {
            System.out.println("this is testNgMethond3");
        }
    }

    testng.xml:

    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
      
    <suite name="Suite1" verbose="1" >
        <test name="Regression1">
            <classes>
                <class name="testNG4" />
                    <methods>
                        <include name="testNgMethond3"></include>
                        <include name="testNgMethond2"></include>
                        <include name="testNgMethond1"></include>
                    </methods>
            </classes>
        </test>
    </suite>
    运行testng.xml,执行结果:
    this is testNgMethond1
    this is testNgMethond2
    this is testNgMethond3
     
    如果想要按照xml中方法的顺序执行,同样在test节点加上preserve-order="true",修改testng.xml如下:
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
      
    <suite name="Suite1" verbose="1" >
        <test name="Regression1" preserve-order="true">
            <classes>
                <class name="testNG4" />
                    <methods>
                        <include name="testNgMethond3"></include>
                        <include name="testNgMethond2"></include>
                        <include name="testNgMethond1"></include>
                    </methods>
            </classes>
        </test>
    </suite>
    再次运行testng.xml,执行结果:
    this is testNgMethond3
    this is testNgMethond2
    this is testNgMethond1
    总之,如果希望xml中的class或者method按照顺序执行的话,就在test节点加上preserve-order="true"
  • 相关阅读:
    linux内核编译步骤
    Linux strace命令
    通过Wifi调试Android应用
    [Java 7][msvcr100.dll] Error when load Eclipse
    Cobar 关系型数据的分布式处理系统
    升级SUSE Linux内核的完整步骤!
    Qt 5.7 亮瞎眼的更新
    QT5.11下载与安装教程
    Delphi 对象模型学习笔记(转)
    内存共享【Delphi版】
  • 原文地址:https://www.cnblogs.com/yuan-yuan/p/4497262.html
Copyright © 2011-2022 走看看