Hi Hemika, It does not matter. You can have "expectedExceptions" attribute with any exception class when the method signature throws Exception class. Cause expectedExceptions will check the instance of thrown exception class with the exception class defined with expectedExceptions. Below sample test method will marked as passed.
@Test( expectedExceptions = {*IOException*.class}) public void testMethod() throws *Exception* { ......... throw new *IOException*("File Not Found"); } Thanks, Nuwanw On Thu, Jul 2, 2015 at 6:53 PM, Hemika Kodikara <hem...@wso2.com> wrote: > Hi Nuwan, > > Sorry for barging in like this. > I agree with your statement, but what if we want to pass a test cases only > if a specific exception is thrown. TestNG allows the "expectedExceptions" > annotation to help this out. See [1]. Else we would have to use a try/catch > to catch the specific exception and then pass or fail the test case using > Assert.fail() method depending on the implementation. > > [1] - http://www.tutorialspoint.com/testng/testng_exception_test.htm > > Regards, > Hemika > > Hemika Kodikara > Software Engineer > WSO2 Inc. > lean . enterprise . middleware > http://wso2.com > > Mobile : +94777688882 > > On Thu, Jul 2, 2015 at 6:16 PM, Nuwan Wimalasekara <nuw...@wso2.com> > wrote: > >> Hi >> >> It is always better to throw the Exception(super class) as a best >> practice when we define a test method rather than throwing the list of >> particular exceptions since no one will catch those exception and handle >> explicitly. Then it will ensure that the test method will not break once >> the methods used within the test method changed and in the test reports It >> shows the actual Exception class. So It will ease the test classes >> maintainability. >> >> @Test() >> public void testMethod() throws *Exception* { >> >> ............ >> } >> >> Thanks, >> Nuwanw >> >> -- >> Nuwan Wimalasekara >> Senior Software Engineer - Test Automation >> WSO2, Inc.: http://wso2.com >> lean. enterprise. middleware >> >> phone: +94 71 668 4620 >> >> >> >> >> _______________________________________________ >> Dev mailing list >> Dev@wso2.org >> http://wso2.org/cgi-bin/mailman/listinfo/dev >> >> > -- Nuwan Wimalasekara Senior Software Engineer - Test Automation WSO2, Inc.: http://wso2.com lean. enterprise. middleware phone: +94 71 668 4620
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev