1

I need some way to execute code before/after each test. This code should be the same for all tests and test cases globally. I was hoping I could use RunListener, but it seems that I need to alter all the tests (or their parent class) to specify custom test runner or use JUnitCore for it to work.

Is there any way I can register this listener without affecting the code base? (there are many many tests and I would need to alter a lot of them for the listener to work)

redhead
  • 1,264
  • 1
  • 17
  • 32

1 Answers1

0

I believe you could use a JUnit Rule feature for it. I assume that all your tests extend some basic test class. So you could add the Rule there.

I think you'll need to implement a custom rule. Quick googling reveals a pretty good tutorial.

halfer
  • 19,824
  • 17
  • 99
  • 186
Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97