@@ -0,0 +1,1669 @@
+package io.github.walterinsh;%0A%0Aimport org.testng.annotations.*;%0A%0A/**%0A * Usually we need to initialize our test cases before we run them. For instance, setting object values,%0A * creating database tables. With testng, we can initialize (also clean)them in different stages.%0A *%0A * Test method with annotation @BeforeClass runs before running the class(all methods).%0A * Test method with annotation @BeforeMethod runs before running every method.%0A *%0A * Output:%0A * Running code before class%0A * Running code before method%0A * Running test one%0A * Running code after method%0A * Running code before method%0A * Running test two%0A * Running code after method%0A * Running code after class%0A *%0A * Here is a great answer about more before annotations and after annotation.%0A * http://stackoverflow.com/questions/30587454/difference-between-beforeclass-and-beforetest-in-testng%0A *%0A * Created by Walter on 11/22/15.%0A */%0Apublic class SetUpAndTearDown %7B%0A%0A    @BeforeClass%0A    public void beforeClass() throws Exception %7B%0A        System.out.println(%22Running code before class%22);%0A    %7D%0A%0A    @BeforeMethod%0A    public void beforeMethod() throws Exception %7B%0A        System.out.println(%22Running code before method%22);%0A    %7D%0A%0A    @Test%0A    public void testOne() throws Exception %7B%0A        System.out.println(%22Running test one%22);%0A    %7D%0A%0A    @Test%0A    public void testTwo() throws Exception %7B%0A        System.out.println(%22Running test two%22);%0A    %7D%0A%0A    @AfterMethod%0A    public void afterMethod() throws Exception %7B%0A        System.out.println(%22Running code after method%22);%0A    %7D%0A%0A    @AfterClass%0A    public void afterClass() throws Exception %7B%0A        System.out.println(%22Running code after class%22);%0A    %7D%0A%7D

add before and after examples