JAVA单元测试框架-6-Enable priority

  1.enabled属性

   在Testng中,如果方法前面添加了@Test注释,然后没有其他的属性,那么默认这个用例会被自动运行。当测试用例没有书写完成,或者不想测试时,可以采用注解@Test(enable=false)来禁止测试用例的执行。Enable属性有两个值true和false。

  @Test(timeOut = 3000,enabled = false)
    public void loginTest(){
        try{
            Thread.sleep(3100);
        }catch (InterruptedException e){
            System.out.println(e.toString());
        }
    }
    @Test
    public void testenable(){
        System.out.println("测试enable");
    }

跳过上面的loginTest测试

 

2.优先级设置priority

有时候,我们更希望,一个类文件下的测试用例按照我们设想的顺序去执行,而不是默认按照方法名的字母排序去执行。

@Test注释中有一个属性,叫priority支持设置用例的优先级。如果不带这个属性,默认priority是等于0,而且priority值越小,优先级越高。来看看下面的举例。

import org.testng.Reporter;
import org.testng.annotations.Test;

public class TestPriority {
	@Test(description="优先级" ,priority= 10)
	public void TestpriorityAdd() {
		Reporter.log(String.valueOf(11+12));
	}
	@Test(description="优先级" ,priority= 2)
	public void Testprioritysub() {
		Reporter.log(String.valueOf(21-12));
	}
	@Test(description="优先级" ,priority= 5)
	public void TestpriorityCat() {
		Reporter.log("cat 喵喵");
	}
	@Test(description="优先级" ,priority= 4)
	public void TestprioritypDog() {
		Reporter.log("dog  汪汪");
	}
	
	@Test(description="优先级" ,priority= 8)
	public void TestpriorityEnglish() {
		Reporter.log("good English");
	}
	@Test(description="优先级" ,priority= 1)
	public void TestpriorityChinese() {
		Reporter.log("good Chinese");
	}
	
	
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员路同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值