Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does JUnit 3 have something analogous to @Ignore

Tags:

java

junit

I'm forced to use JUnit 3. If I were using JUnit 4, I would occasionally use @Ignore since several of my tests take a bit of time.

Is there anything analogous in JUnit 4? Commenting out tests is sloppy, and changing the name (from testXxx()) could lead to forgotten tests. @Ignore is great, because it always reminds you which tests were not run.

Does anyone have a best practice for running some of a test classes methods in JUnit 3?

like image 343
Eric Wilson Avatar asked Jun 17 '10 12:06

Eric Wilson


People also ask

What is @ignore in JUnit?

The @Ignore annotation helps in this scenario. A test method annotated with @Ignore will not be executed. If a test class is annotated with @Ignore, then none of its test methods will be executed.

How do you stop a JUnit test?

You press the 'Stop JUnit test run' wanting to halt the execution immediately. And it doesn't! Then you must go to the Debug view (why that name? i'm not debugging, i'm running) and 'Terminate' it from there.


2 Answers

In order to conditionally ignore tests in Robotium / JUnit 3, I override runTest() like

@Override protected void runTest() throws Throwable {     // Do nothing if the precondition does not hold.     if (precondition) {         super.runTest();     } } 

Tests which are ignored this way will show up as "Success" in Eclipse, but as there is no "Ignored" state with JUnit 3, this is the best I was able to get.

like image 37
sschuberth Avatar answered Sep 18 '22 10:09

sschuberth


I don't know any other solution apart from commenting out tests or renaming them. I would go for the renaming option and use my own convention. For example all of them will start with ignoreXXX(). Then you can do one find/replace with your editor and you are ready.

like image 170
Petar Minchev Avatar answered Sep 22 '22 10:09

Petar Minchev