TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

JUnit

@Ignore annotation in JUnit

JUnit Tutorial

Overview

In this post, we will learn how to ignore tests in JUnit. To ignore a test we use @Ignore annotation. @Ignore annotated method would not be executed and would be ignored by JUnit. The method annotated with ignore will be skipped.

Sample JUnit Test class

package com.testingdocs.junit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

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


public class IgnoreTestInJUnit {

 @Ignore
 @Test
 public void ignoreTestMethod() {
 System.out.println("This method will NOT run. ");
 }

 @Test
 public void executeTestMethod() {
 System.out.println("This method will run. Unless ignored at class level.");
 assertEquals(5,5);
 }
}

In the above code the first method is annotated with @Ignore annotation. This method will be skipped.

 

Class level annotation

We can use the annotation at class level. If you use the annotation at the class level, all the tests in the class would be ignored during the test run. All the methods will be skipped.

package com.testingdocs.junit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

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

@Ignore
public class IgnoreTestInJUnit {

 @Ignore
 @Test
 public void ignoreTestMethod() {
 System.out.println("This method will NOT run. ");
 }

 @Test
 public void executeTestMethod() {
 System.out.println("This method will run. Unless ignored at class level.");
 assertEquals(5,5);
 }
}

 

 

 

Related Posts

JUnit /

Getting Started with JUnit Framework

JUnit /

Run JUnit tests from command line

JUnit /

Working with JUnit in Eclipse IDE

JUnit /

Adding JUnit5 library to a Project

JUnit /

Debug JUnit Tests using IDE

‹ Disadvantages of using Inherited tests in JUnit› Differences between JUnit 3 and JUnit 4

Recent Posts

  • Scaler Academy – An Online Learning Platform
  • Difference between PHP and JavaScript?
  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com