Currently I'm working on Selenium tests with Gradle(groovy), Gebish and jUnit4.
In my gradle.build I have variables for the test environment (wich server local or live and wich domain).
Now I want that not all tests run in each case. For example I want that TestA and TestB run with domain abc.com and only TestA and TestC run with domain def.com
For that I created a global config class where I get the information wich class is allowed to run.
My idea is run an @before before each method and check if the class is allowed, but I don't know how to skip after @before.
Is there a simple way for that? Is it possible to use something like System.exit(0) to just exit the test class and not the whole test?
You can use the methods of
org.junit.Assume. They are like the methods in
org.junit.Assert, but they will not fail the test like those but skip them on failure. This method is usable if you want put that control code inside the test classes.
Other than that you could also use JUnit Categories to mark a test or a test class as "run against a" and / or "run against b" and then make the decision which categories to run in your Gradle file.
The difference between these two approaches - besides where the decision code is hosted - is, that with the first solution you get the skipped tests as "ignored" or "skipped" in the test report while with the second solution only the tests belonging to the specified categories are run and thus are shown in the test report.