This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bluemoon.main; | |
import org.testng.annotations.*; | |
import org.testng.annotations.Test; | |
/** | |
* Created by chris_jeng on 2015/8/4. | |
*/ | |
public class TestTest { | |
@BeforeSuite | |
public void testBeforeSuite() throws Exception { | |
System.out.println("BeforeSuite"); | |
} | |
@BeforeGroups(groups = "1") | |
public void testBeforeGroups() throws Exception { | |
System.out.println("BeforeGroups"); | |
} | |
@BeforeClass | |
public void testBeforeClass() throws Exception { | |
System.out.println("BeforeClass"); | |
} | |
@BeforeTest | |
public void testBeforeTest() throws Exception { | |
System.out.println("BeforeTest"); | |
} | |
@BeforeMethod | |
public void testBeforeMethod() throws Exception { | |
System.out.println("BeforeMethod"); | |
} | |
@Test(groups = "1") | |
public void test() { | |
System.out.println("Test"); | |
} | |
@Test(groups = "1") | |
public void test2() { | |
System.out.println("Test2"); | |
} | |
@AfterMethod | |
public void testAfterMethod() throws Exception { | |
System.out.println("AfterMethod"); | |
} | |
@AfterTest | |
public void testAfterTest() throws Exception { | |
System.out.println("AfterTest"); | |
} | |
@AfterClass | |
public void testAfterClass() throws Exception { | |
System.out.println("AfterClass"); | |
} | |
@AfterGroups(groups = "1") | |
public void testAfterGroups() throws Exception { | |
System.out.println("AfterGroups"); | |
} | |
@AfterSuite | |
public void testAfterSuite() throws Exception { | |
System.out.println("AfterSuite"); | |
} | |
} |
執行結果為
BeforeSuite
BeforeTest
BeforeClass
BeforeGroups
BeforeMethod
Test
AfterMethod
BeforeMethod
Test2
AfterMethod
AfterGroups
AfterClass
AfterTest
AfterSuite
藉此了解用法與執行順序
參考
http://www.cnblogs.com/TankXiao/p/3888070.html
留言
張貼留言
有什麼想法歡迎跟我們分享