JUnit – Ignore Test

Sometimes, it is required not to execute any testcase. So by using @Ignore annotation, you can bypass any testcase. Following example demonstrates how to ignore a testcase.

First create a new Java Project and configure it as Maven Project. For Reference, Click Here

Add the following dependencies in pom.xml

  <dependencies>
   	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>4.10</version>
	</dependency>
  </dependencies>

1. JUnit Class

Create following class

package com.kruders.junit;

import static org.junit.Assert.assertEquals;

import org.junit.Ignore;
import org.junit.Test;

public class JUnitIgnoreTest {
	@Test
	public void testAdd(){
		assertEquals(15, 10 + 5);
		System.out.println("@Test called - Addition");
	}
	
	@Ignore
	@Test
	public void testSubtract(){
		assertEquals(5, 10 - 5);
		System.out.println("@Test called - Subtraction");
	}
}

2. Testing

When you run the above example you’ll get an output like:

@Test called – Addition


No comments yet.

Leave a Reply