TESTNG注解

5 篇文章 0 订阅
4 篇文章 0 订阅

一:TestNG常用注解

package com.lh.practice.testng;

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class testNG {
	@BeforeSuite
	public void beforesuit() {
		System.out.println("BeforeSuite");
	}
	@BeforeTest
	public void BeforeTest() {
		System.out.println("BeforeTest");
	}
	@BeforeClass
	public void BeforeClass() {
		System.out.println("BeforeClass");
	}
	@BeforeMethod
	public void BeforeMethod() {
		System.out.println("BeforeMethod");
	}
	@Test
	public void test1() {
		System.out.println("this is test1");
	}
	@Test
	public void test2() {
		System.out.println("this is test1");
	}
	@AfterSuite
	public void AfterSuite() {
		System.out.println("AfterSuite");
	}
	@AfterTest
	public void AfterTest() {
		System.out.println("AfterTest");
	}
	@AfterClass
	public void AfterClass() {
		System.out.println("AfterClass");
	}
	@AfterMethod
	public void AfterMethod() {
		System.out.println("AfterMethod");
	}
	
	

}

 二、depend依赖

package com.lh.practice.testng;

import org.testng.annotations.Test;

public class depend {
	@Test
	public void test1() {
		System.out.println("sys1");
	}
	@Test(dependsOnMethods= {"test1"})
	public void test2() {
		System.out.println("sys2");
	}

}

三、忽略

package com.lh.practice.testng;

import org.testng.annotations.Test;

public class ignoreTest {

	@Test(enabled = false)
	public void ingore() {
		System.out.println("this is ingore");
	}

	@Test
	public void noIngore() {
		System.out.println("this is noIngore");
	}

	@Test(enabled = true)
	public void Ingore2() {
		System.out.println("this is noIngore2");
	}

}

4、超时

package com.lh.practice.testng;

import org.testng.annotations.Test;

public class timeOutTest {
	@Test(timeOut = 3000)
	public void testSuccess() throws InterruptedException {
		Thread.sleep(2000);
	}

	@Test(timeOut = 3000)
	public void testUnSuccess() throws InterruptedException {
		Thread.sleep(4000);
	}

}

5、传参

package com.lh.practice.testng.paramter;

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class parameterTest {
	@Test
	@Parameters({"name","age"})
	public void parameter(String name,int age) {
		System.out.println("my Name is"+" "+name+"\n"+"my Age is"+" "+age);
	}

}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">


<suite name="parameter">
  <test thread-count="5" name="Test">
  	<parameter name="name" value="lh"/>
    <parameter name="age" value="26"/>
	<classes>
      <class name="com.lh.practice.testng.paramter.parameterTest"></class>
	</classes>

  </test>
</suite> <!-- Suite -->

5、分组

package com.lh.practice.testng.groups;

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class groupsOnMethod {
	@Test(groups="server")
	public void test1() {
		System.out.println("这是服务端组的测试方法111111");
	}
	@Test(groups="server")
	public void test2() {
		System.out.println("这是服务端组的测试方法222222");
	}
	@Test(groups="client")
	public void test3() {
		System.out.println("这是客户端组的测试方法111111");
	}
	@Test(groups="client")
	public void test4() {
		System.out.println("这是客户端组的测试方法222222");
	}
	
	@BeforeGroups(groups="server")
	public void serverBeforeGroups() {
		System.out.println("这是服务端之前运行的方法");
	}
	@AfterGroups(groups="server")
	public void serverAfterGroups() {
		System.out.println("这是服务端之前运行的方法");
	}


}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值