I have a question about how to handle tearDown of JUnit tests (in Gradle) when you have multiple test classes.
Here is the problem:
JUnit doesn’t have a @AfterSuite annotation like TestNG has for test groups. 2. The @AfterClass annotation works fine where all your tests are in one single class but that is not my question. 3. If you have multiple JUnit classes , each with their own set of tests, and all of the classes need to share a
static object of some kind, such as a web browser object, in that case the tearDown in @AfterClass would destroy
the static object between classes which isn’t acceptable for performance reasons. Destroying and recreating an
object over and over again unnecessarily is inefficient.
So, how can Gradle solve this issue for me?
Is the Gradle JUnit Runner capable of something similar to @AfterSuite ?
Depending on the kind of work, you can either do it in the build (before/after running a particular test task), or use JUnit test suites (see the JUnit docs).
I tried that already but when I ran the JUnit test suite, the Gradle “Runner” still picks up all the other tests classes, therefore running all tests TWICE.
Not sure why the Runner does this.
I was expecting the Runner to “detect there is a suite” and run only the suite.
Also, what if I have more than one suite/group of tests. Is this something that the Gradle Eclipse Tooling plugin is supposed to handle or am I overlooking some way that Gradle itself has that already exists to handle this?
I believe I tried using -Dtest.single
but the Runner still picks up the other tests .
If you are so sure it works, I will try again, it is very possible I have a config problem, but I am not convinced after trying it once already.
It’s something that you have to deal with yourself, by declaring one or multiple test tasks which run the suites you want them to run, and nothing else.
Is there a way to get the test report to show the Suite classes? Currently, in the test report, if I click on the suite, it just shows the list of all method names in the suite WITHOUT any information about what class each method belongs to.