(XI) TestNG other tips

In addition to the functions described previously, TestNG there are some tips, relatively simple, here to demonstrate with an example.

Other tips


import org.testng.annotations.Test;
import static org.testng.AssertJUnit.assertEquals;


public class OtherTest { // 该条用例跳过执行 @Test(enabled = false) publicvoidtestCase1(){ assertEquals(2+2, 4); } // 设定用例超时时间 @Test(timeOut = 3000) publicvoidtestCase2()throws InterruptedException { Thread.sleep(3001); } // 预设用例抛出的异常类型 @Test(expectedExceptions = RuntimeException.class) publicvoidtestCase3(){ assertEquals(2/0,1); } } 
  • Example enabled by setting whether to skip execution, default: true, it indicates not skipped. false to skip execution.

  • timeOut embodiment is provided with running super time, 3000 milliseconds, when the operating cases with more than 3000 ms is determined as a failure. Regardless of whether patients themselves fail.

  • expectedExceptions used to preset the abnormal case operation will occur. For example 2/0 will throw RuntimeException type of exception, if an exception occurs it means that the successful implementation of use cases.

Guess you like

Origin www.cnblogs.com/xinlan06/p/11498789.html