What do I have now (example code, just fore more clear explanation).
Class which is used for running all tests:
Test classes (FirstTest, SecondTest) uses field "id", which is declared in their common super class somehow like this:
So, what do I need.
Want to write class AllMultiIdsTests, which also will be responsible for running test classes FirstTest and SecondTest.
But unlike AllTests, it would be do it for ids collection.
Something like this:
Or it's also possible to rewrite FirstTest, SecondTest in a way when they will use single id or ids collection in depend on some new field. But I also need to pass value of this field from AllMultiIdsTests and AllTests... How can I do it?
For now I haven't found anything related to configuring Test classes from class which run them all...
PS: Sorry for any errors in English if there are some. Thanks.
Welcome to CodeRanch! This is an interesting question. I can think of two approaches.
Option 1 If you add the same test multiple times, JUnit will run it. This means you can create a dummy test where the the test itself sets the property.
1) The suite is still a JUnit test.
2) You get one set of output
1) You are relying on JUnit continuing to run the tests in the same order as specified in the test suite. It is documented that the order isn't guaranteed so you would be introducing code that relies on a side effect.
2) It isn't apparent which test has failed. (You can mitigate this by having DummyTestToSetProperty output what the current property is.)
Option 2 Run the test suite itself multiple times from a main method.
1) Cleaner and not subject to a side effect
1) Runs multiple suites with separate output. Could be a problem for your build tool