1

I have several Junit/Selenium WebDriver tests, each one in separate class. Still I have not been able to implement methods which should be run before and after ALL tests are run. Not before or after class, because then they run before and after every test.

I must implement some sort of test suite, but how that is done e.g without adding all the classes manually to suite?

Prasad
  • 472
  • 5
  • 15
mjgirl
  • 1,214
  • 7
  • 24
  • 42
  • How is it that you are running these tests? Is it command line, IDE or some build tool like Maven or Ant? – Eugen Oct 23 '12 at 11:20
  • One method is explained here: http://stackoverflow.com/questions/3007425/how-to-load-dbunit-test-data-once-per-case-with-spring-test/9006655#9006655 – Kkkev Oct 27 '12 at 07:04

2 Answers2

2

Have a look at this QA. It is about having a method that executes before a test suite runs.

You need to have a static method annotated with BeforeClass in your test suite. Your test suite references all test classes, but have a look at the example in the QA and you will see it's not that tedious when you use the Suite runner with thes @SuiteClasses annotation.

I don't know any built-in method you could use to add the test cases to the suite otherwise than manually.

Community
  • 1
  • 1
Alban
  • 1,915
  • 1
  • 14
  • 17
  • How about adding the tests to suite with package names or file extensions? – mjgirl Oct 24 '12 at 05:38
  • As I wrote above, I'm not aware of any built-in solution to your problem. So I would extend the `Suite` runner (code [here](http://www.docjar.com/html/api/org/junit/runners/Suite.java.html)), defining a custom annotation representing the packages where your tests live. Then at initialization time, use the [reflexions library](http://code.google.com/p/reflections/) to discover the test classes. – Alban Oct 24 '12 at 07:51
0

I don't know if JUnit is able to do the things you want. You might want to try TestNG. You don't need to change your Test but you can do stuff like @BeforeSuite to run a method before every test you got in that suite. Klick here

Tarken
  • 2,112
  • 2
  • 23
  • 42