3

I use JUnit 3.x TestRunner that intantiates all tests at once before running them.

Is there a Test Runner available that would create each test (or at least each test suite's tests) just before running them?
I can use JUnit 4.x runners but my tests are 3.x tests.

topchef
  • 19,091
  • 9
  • 63
  • 102
  • Could you please provide some more information why you need to do this? I'm not the only one who suspects there's something more to know. – guerda Jul 29 '09 at 07:41
  • We have some extensive test infrastructure code that helps us organize test environment and test data. Unfortunately, some tests use constructor and some tests use setUp to drive it. The issue we are having is time-related. Rather than refactoring to move things from constructors to setUp it would be easier to have constructor to run just before setUp. – topchef Jul 29 '09 at 21:03
  • Also, I can't see any significant difference between unit test framework creating tests (execute constructors) JIT or lining them up before tests run. – topchef Jul 29 '09 at 21:06

2 Answers2

3

In JUnit 3 you'd need to write your own TestSuite class that delayed instantiation of the tests in the suite.

Nat
  • 9,820
  • 3
  • 31
  • 33
1

You are probably doing it wrong.

Each unit test should be self-contained and not depend on any other test results. Otherwise when one of the tests break it will break all the tests that depend on it. So you will see a lot of errors without easy way to understand what is the actual cause. On the other hand if all unit tests are independent a broken test is extremely easy to debug and fix.

EDIT: I am assuming the reason you ask the original question is because you have some dependencies in your test. If I am wrong please ignore this answer :)

Gregory Mostizky
  • 7,231
  • 1
  • 26
  • 29