Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 436781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:30:45+00:00 2026-05-12T20:30:45+00:00

OK, so the @Ignore annotation is good for marking that a test case shouldn’t

  • 0

OK, so the @Ignore annotation is good for marking that a test case shouldn’t be run.

However, sometimes I want to ignore a test based on runtime information. An example might be if I have a concurrency test that needs to be run on a machine with a certain number of cores. If this test were run on a uniprocessor machine, I don’t think it would be correct to just pass the test (since it hasn’t been run), and it certainly wouldn’t be right to fail the test and break the build.

So I want to be able to ignore tests at runtime, as this seems like the right outcome (since the test framework will allow the build to pass but record that the tests weren’t run). I’m fairly sure that the annotation won’t give me this flexibility, and suspect that I’ll need to manually create the test suite for the class in question. However, the documentation doesn’t mention anything about this and looking through the API it’s also not clear how this would be done programmatically (i.e. how do I programatically create an instance of Test or similar that is equivalent to that created by the @Ignore annotation?).

If anyone has done something similar in the past, or has a bright idea of how else I could go about this, I’d be happy to hear about it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T20:30:45+00:00Added an answer on May 12, 2026 at 8:30 pm

    The JUnit way is to do this at run-time is org.junit.Assume.

     @Before
     public void beforeMethod() {
         org.junit.Assume.assumeTrue(someCondition());
         // rest of setup.
     }
    

    You can do it in a @Before method or in the test itself, but not in an @After method. If you do it in the test itself, your @Before method will get run. You can also do it within @BeforeClass to prevent class initialization.

    An assumption failure causes the test to be ignored.

    Edit: To compare with the @RunIf annotation from junit-ext, their sample code would look like this:

    @Test
    public void calculateTotalSalary() {
        assumeThat(Database.connect(), is(notNull()));
        //test code below.
    }
    

    Not to mention that it is much easier to capture and use the connection from the Database.connect() method this way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to ignore multiple wildcard routes. With asp.net mvc preview 4, they ship
How do I ignore files in Subversion? Also, how do I find files which
How can I ignore accents (like ´, `, ~) in queries made to a
How can I ignore directories or folders in Git using msysgit on Windows?
How can one ignore Unexpected element situation in JAXB ans still get all other
Let us ignore for a moment Damian Conway's best practice of no more than
How can I ignore an output parameter of a stored procedure? I'm calling the
What is the best SVN Ignore Pattern should TortoiseSVN have for a VB.NET solution?
How do I make diff ignore temporary files like foo.c~ ? Is there a
Seems to me most of developers completely ignore this features. People prefer handling security

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.