What is the purpose of the @Ignore annotation in unit testing?
Either a test will be green and everything is fine or it is red so you fix it before commit. So if there is an ignored test, it is the same thing as dead code and we know what to do with that: delete it! Keep the code clean!
Now, there is actually a proper use of the @Ignore annotation, that is when you are refactoring the design.
You still can’t commit code with ignored tests as this will be confusing if spotted by a fellow programmers. But for a while, in your isolation you can find it useful to live with.
The scenario I’m thinking of is when you happily do your TDD test-implement-refactor cycle and run into a dead end in your design. You have written a failing test and discovered that, to create an implementation for the test, you must change the design. But when refactoring, you need to been in the green state, i e no failing tests. So what do you do?
The failing test must go away and you have two options, hide it with comments or use the @Ignore annotation. The latter is the better since while doing the redesign, you will have the test come up in your IDE as ignored during each run.
That way, you will never loose track of what got you started with the refactoring while you still can look for failing tests during the refactoring.
Once the redesign is done, you remove the ignore annotation and implement to pass the test. You have taken a big step forward without loosing control for a single moment.
Then you commit.
This is the single case I can think of that justifies the use of the @Ignore annotation.
Update: I know of a second case now, see comments. 🙂