JUnit @Ignore Annotation: How to Skip Tests
Use JUnit 4’s @Ignore to skip a test or class while keeping it visible in reports. Learn the JUnit Jupiter equivalent and migration options.
In JUnit 4, annotate a test method with @Ignore to skip it, or annotate the test class to skip its contained tests. Add a short reason so the test report and future maintainers can tell why it is disabled. In JUnit Jupiter (JUnit 5), use @Disabled instead.
1. Skip one test in JUnit 4
Import org.junit.Ignore and place it on a method that is also annotated with @Test. The optional string is the reason; it defaults to an empty string. JUnit 4 runners recognize the annotation and report the test as ignored rather than running its body. [JUnit 4.13.2 API] [JUnit team guide]
import org.junit.Ignore;
import org.junit.Test;
public class PaymentTest {
@Ignore("Disabled until the test gateway is available")
@Test
public void chargesCard() {
// This body is not executed while the test is ignored.
}
@Test
public void rejectsExpiredCard() {
// This test still runs.
}
}
The example assumes JUnit 4 is already on the test classpath and that the project runs this class with a JUnit 4 runner. The test method must have @Test; @Ignore alone does not make a method a test.
Where to put the annotation
- One method: put
@Ignore("reason")on that test method. - Every test in a class: put
@Ignore("reason")on the class declaration. - No reason available: the reason is optional, but a concise explanation is more useful than a bare annotation.
import org.junit.Ignore;
import org.junit.Test;
@Ignore("Integration environment is being rebuilt")
public class RemoteServiceTest {
@Test
public void fetchesAccount() { }
@Test
public void updatesAccount() { }
}
JUnit 4’s annotation targets methods and types and is retained at runtime, allowing compatible runners to act on it. The class-level form disables the contained tests. [JUnit 4 API]
2. What an ignored test means
An ignored test is still present in source and visible to JUnit’s reporting. Native JUnit 4 runners report ignored-test counts along with tests run and failures. That makes @Ignore useful for temporary disablement when you want the skipped test to remain discoverable. [JUnit team guide]
Commenting out a test or removing @Test also prevents execution, but the runner no longer reports it as an ignored test. Prefer @Ignore when the test should stay visible and have an explicit reason. Remove the annotation once the underlying issue is fixed; ignored tests do not provide coverage while disabled.
3. JUnit Jupiter: use @Disabled
JUnit Jupiter does not natively use JUnit 4’s org.junit.Ignore. Its corresponding annotation is org.junit.jupiter.api.Disabled, which can be applied to a test method or class. Include a reason here too. [JUnit 5 User Guide: disabling tests]
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
class PaymentTest {
@Disabled("Waiting for the replacement test gateway")
@Test
void chargesCard() {
// Not executed by Jupiter while disabled.
}
@Test
void rejectsExpiredCard() {
// Still runs.
}
}
For a Jupiter class, annotate the class with @Disabled("reason") to disable its tests. Check the imports: org.junit.Ignore belongs to JUnit 4, while org.junit.jupiter.api.Disabled is Jupiter’s native choice.
4. Keeping legacy @Ignore in a Jupiter migration
If a migration requires existing JUnit 4 @Ignore annotations to keep working in Jupiter, use JUnit’s migration-support module and register its ignore condition. The JUnit guide documents either direct registration with @ExtendWith or the composed @EnableJUnit4MigrationSupport annotation. This is a compatibility path; for new Jupiter tests, prefer @Disabled. [JUnit 5 migration support guide]
// Add the junit-jupiter-migrationsupport artifact at the same version
// as the project's other JUnit Jupiter artifacts.
import org.junit.Ignore;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.migrationsupport由.junit4.IgnoreCondition;
@ExtendWith(IgnoreCondition.class)
class LegacyPaymentTest {
@Ignore("Kept during the JUnit 4 migration")
@Test
void chargesCard() { }
}
Alternatively, use the migration-support annotation, which registers the condition for the test class:
import org.junit.Ignore;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.migrationsupport.EnableJUnit4MigrationSupport;
@EnableJUnit4MigrationSupport
class LegacyPaymentTest {
@Ignore("Kept during the JUnit 4 migration")
@Test
void chargesCard() { }
}
Import note: the condition’s package is org.junit.jupiter.migrationsupport; use org.junit.jupiter.migrationsupport.IgnoreCondition in the first example. Keep the migration-support dependency and the JUnit platform/Jupiter versions aligned with the versions used by your project. The guide’s migration support applies to legacy ignored classes and methods; it does not turn JUnit 4’s annotation into Jupiter’s native API.
5. Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The test still runs | The class is being run by Jupiter, which does not natively interpret JUnit 4 @Ignore. |
Use Jupiter’s @Disabled, or configure the documented migration-support dependency and condition. |
| The method is missing from the report | @Test was removed or the method was commented out. |
Keep @Test and add @Ignore("reason") so a JUnit 4 runner can report it as ignored. |
| Other tests in the class also skip | @Ignore is on the class declaration. |
Move it to only the method that should be disabled. |
| A JUnit annotation import is unresolved | The source uses an annotation from a different JUnit generation, or its dependency is missing. | For JUnit 4, check the JUnit 4 dependency and org.junit.Ignore. For Jupiter, check Jupiter API and org.junit.jupiter.api.Disabled. For migration support, add the matching migrationsupport artifact. |
| Migration support does not disable a legacy test | The migration condition is not registered or the test is not running on the Jupiter engine. | Register IgnoreCondition with @ExtendWith or use @EnableJUnit4MigrationSupport, and verify the test is executed by Jupiter. |
6. Practical guidance
- Make the reason actionable: mention the condition for re-enabling the test, such as the defect or unavailable dependency, rather than writing “disabled.”
- Keep the disabled set small: ignored tests do not catch regressions. Track and revisit them when the stated blocker changes.
- Use the annotation for a deliberate skip: it does not repair a flaky test, make a slow test faster, or conditionally retry a failure.
- Check the runner and engine: annotation behavior depends on whether the project executes the test with JUnit 4 or Jupiter.
Ignoring a test has negligible runtime cost because the test body is not run. The larger reliability cost is loss of coverage for the behavior it was meant to verify. JUnit’s documentation does not specify a financial cost or performance benchmark for the annotation.
7. Or skip the browser setup
This JUnit guide is about test annotations. If a test workflow also needs website screenshots, ScreenshotNeo provides a screenshot API and MCP server. A single GET request captures a URL as an image or PDF. Here is a runnable cURL example; create an API key and see the ScreenshotNeo API documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" \
-d access_key=YOUR_API_KEY \
--data-urlencode url=https://stripe.com \
-o shot.webp
Equivalent Python and Node.js requests:
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({
access_key: 'YOUR_API_KEY',
url: 'https://stripe.com'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);
Cookie banners are accepted and removed before capture, along with supported newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, with response headers indicating the page verdict and billing status. AI agents can use the MCP server’s take_screenshot, get_page_info, and capture_pdf tools. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up for ScreenshotNeo’s free plan and get 1,000 screenshots a month with no card.
8. FAQ
Does @Ignore delete or remove a test?
No. The method remains in source and is reported as ignored by a compatible JUnit 4 runner.
Can @Ignore disable an entire test class?
Yes. In JUnit 4, place it on the class to disable the tests it contains.
Should new JUnit 5 tests use @Ignore?
No. Use org.junit.jupiter.api.Disabled for Jupiter tests. Reserve migration support for legacy annotations that need compatibility.
Does adding a reason change how the test is skipped?
No. The string documents why the test is ignored; the annotation’s value is optional.


