Ignore Test In Junit

How to Skip a Test using Junit?
If there are 4 total Tests to be executed and we have scenario to skip one test and execute the remaining Tests then we need to use @Ignore annotation.

How do we use @Ignore?
We need to select the test which we wanted to skip and place the @ignore annotation before the @Test method.

Instead of using @Ignore annotation , if I comment the @Test is this the correct approach?
No, this is not the correct approach because

The commented @Test will not be reported to the result. All the ignored tests will be displayed in different colour while reporting.
When there are many @Test adding on daily basis, we may not run this @Test or forget about this commented @Test.
Example of @Ignore Annotation :


OUTPUT :

Junit-IgnoreTest-Example

Why do I need to use this @Ignore test for certain @Test?
There are scenarios where in @Test there are tests(scripts) being created or failing due to some object repository changes.
And if we want to find exact count of passed and Failed tests for a batch run eliminating the under construction scripts.
Send report to customer after the test script Execution.

Leave a Comment

Your email address will not be published. Required fields are marked *