mjgirl
mjgirl

Reputation: 1234

Do something before and after tests

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?

Upvotes: 1

Views: 960

Answers (2)

Alban
Alban

Reputation: 1943

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.

Upvotes: 2

Tarken
Tarken

Reputation: 2202

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

Upvotes: 0

Related Questions