lundi 15 juin 2020

Testng - testing exceptions based on invocations

I have 3 different method invocations in the below try block. I need to test if the method in finally block is being invoked when there is an exception in either of the 3 methods in try block. My idea is to throw exception in method1() and not in method2() and method3() and test if method4() is being invoked. I'd like to repeat the same but this time, I'll throw an exception in method2() and not in method1() and method2().

Can I use DataProvider to achieve this? If so, how?

For example, My class:

public class TestClass(){

    try {
        method1();
        method2();
        method3();
    }

    catch(Exception e) {
        System.out.println(e);
    }

    finally{
        method4();
    }   
}

My Test:

@Test(invocationCount=3)
public void testMethod(){
test();
}

Aucun commentaire:

Enregistrer un commentaire