21

Before stepping into the TDD cycle, I like to sketch out the tests that need to be implemented - i.e. write empty test methods with speaking names.

Unfortunately I have not found a way to "paint them yellow" - mark them as pending for JUnit. I can make them either fail or pass. Now I am letting them fail by throwing an Exception, but I'd rather use an equivalent of pending from rspec.

Is there such an option in JUnit or an "adjacent" library?

kostja
  • 60,521
  • 48
  • 179
  • 224
  • 2
    I've personally used `throw new UnsupportedOperationException("not yet implemented")` as an eclipse/intellij template. – eis Jan 15 '13 at 15:47

2 Answers2

35

You can use @Ignore to ignore the test,

or this library to introduce the @PendingImplementation annotation:

https://github.com/ttsui/pending

I don't think there are other ways to achieve this..

mkobit
  • 43,979
  • 12
  • 156
  • 150
Enrichman
  • 11,157
  • 11
  • 67
  • 101
  • Thank you. I'll go with the pending lib from Tony Tsui. It's a pity that JUnit only offers a "skipped" semantics, but it's still the closest thing – kostja Jan 15 '13 at 16:11
  • 5
    +1 Even better with a comment in the @Ignore("not ready yet") – Matthew Farwell Jan 15 '13 at 16:11
  • 3
    @MatthewFarwell I find that to be much less useful semantics `@PendingImplementation` is better because it will still try to execute your test, and let you know if the test actually passes, which reminds you to remove the annotation. Plus it's more descriptive and searchable. – Grundlefleck Aug 31 '13 at 16:39
  • Is there anything like this for Junit5? – Marcin Erbel Oct 05 '22 at 10:29
  • https://junit.org/junit5/docs/current/user-guide/#writing-tests-disabling for junit5 – lucapette Jan 14 '23 at 07:18
4

You could use Assume or @Ignore, both are not quite what you are after but close. The 3rd party library pending also exists. I have not used it, but appears to do what you want.

Michael Lloyd Lee mlk
  • 14,561
  • 3
  • 44
  • 81