Kochetov
Kochetov

Reputation: 31

TestNG one test for two classes

I have TestNG tests in some classes, which extends the same main class. I need the same last test for class1 and class2, but if I add @Test(priority = 666) to main class it start after all classes. How I should annotate @Test in main class what would it starts after all tests of each class?

Big thanks. Also sorry for bad english.

main class

    public class MainTest {

    @BeforeClass()
    public void setup() {
    //something 
    }

    @AfterClass()
    public void tearDown() {
    //something
    }

    @AfterMethod()
    public void log_writer(Method method) {
    //something
           }

    @Test(priority = 666) {}
    }

class1

    public class Class1 extends MainTest {

    @Test
    public void test1(){}

    @Test
    public void test2(){}  

    }

and class2

    public class Class2 extends MainTest {

    @Test
    public void test1(){}

    @Test
    public void test2(){}  
    }

Upvotes: 0

Views: 177

Answers (2)

Jaroslav Cincera
Jaroslav Cincera

Reputation: 1036

It's not possible. Basically each @Test runs only once. If you need to do something after each test class you have to use @AfterClass annotation on method in your MainTest. You can do some hacks with method order etc. in MethodInterceptor (http://testng.org/doc/documentation-main.html#methodinterceptors) but it's not good idea for this case.

Upvotes: 0

Gosaka
Gosaka

Reputation: 191

what you are looking for is the @AfterClass annotation. handle the part where you want to check logs in the AfterClass annotated method

Upvotes: 1

Related Questions