Conditional testing with ITestAnnotation interface

In TestNG there is provision that we can run tests conditionally, like we can have test case that needed to be executed with flags yes or no and we want to conditionally run these tests.

For this purpose we can make use of ITestAnnotation interface. This provides the interface to override the test annotations during runtime.

TestNG_ItestAnnotation

The above example is listener class that can override the transform method, which dictates the test annotation. We can control the enabled annotation attribute to make test available to pickup by the TestNG framework.

Make sure that you have enabled annotation available for the test. I.E explicitly add this annotation for the test so that, TestNG overrides the Annotation. If this attribute is not there TestNG cannot  override the same.

TestNG_ITestAnnotation_Enabled

And finally add this listener to TestNG XML to make things work.

TestNG_XML

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s