• 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"
  • 相关阅读:
    关于xampp 集成开发包电脑重启mysql无法启动的问题
    ThinkPhP html原样入库
    java 获取图片大小(尺寸)
    xampps 不能配置非安装目录虚拟主机解决方案
    从0开始 java 网站开发(jsp)【1】
    Hello world!
    SpringMVC归纳-1(model数据模型与重定向传参技术)
    TTL与非门电路分析
    git入门手册:git的基本安装,本地库管理,远程上传
    实现简单的评论区功能
  • 原文地址:https://www.cnblogs.com/yuan-yuan/p/4497262.html
Copyright © 2020-2023  润新知