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"
  • 相关阅读:
    【代码笔记】iOS-关于UIFont的一些define
    【代码笔记】iOS-根据size截取屏幕中间矩形区域
    【代码笔记】iOS-给UIImageView加上圆角效果
    【代码笔记】iOS-给背景图加上移动的手势
    【代码笔记】iOS-给背景图赋值颜色
    【代码笔记】iOS-点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多。
    【代码笔记】iOS-钢琴小游戏
    【代码笔记】iOS-改变文字输入框背景
    【代码笔记】iOS-浮动的云
    【代码笔记】iOS-浮点数处理并去掉多余的0
  • 原文地址:https://www.cnblogs.com/yuan-yuan/p/4497262.html
Copyright © 2011-2022 走看看