For more details see the documentation, chapters: “How to group tests into suites” and “How to specify SETUP or TEARDOWN procedures”.
What you are asking is already done by default. The suite setup is not a setup that the suite itself needs/depends on. It is rather a setup that is common to each of the individual tests in the suite. When you run a test, the setup will be executed
regardless if you run the test individually or if you run the entire suite. If you run the entire suite, the setup (and optionally the teardown) will not wrap the execution of the suite. It will wrap the execution of each test.
There is one point where you may disagree with the current behavior. In your posting where you say: “This should be optional as you may not want to run the setup depending on the actual test”. If you have a test that does not have a setup you
can always place it in a different suite or write it outside of any suite. If you have a test that needs a setup then I would argue that the setup needs to be run regardless of the fact that the test is run individually or as part of the suite. Remember that
tests are supposed to be independent and that they are also wrapped each in their own transaction to facilitate the isolation between different tests. Having said this, if you disagree please give me some info about your scenario.
Here are some more details to make sure things are clear. Let’s assume you have the following stored procedures:
If you run the test ”SQLTest_SuiteX#TestA” then the procedures will be run in this order:
If you run the suite ”SuiteX” then the procedures will be run in this order:
The actual logic is a little bit more complex because you could also have optional teardown procedures, automatic rollback and setup/teardown at the test session level. For the complete picture see the documentation, chapters: “How to group tests into
suites” and “How to specify SETUP or TEARDOWN procedures”.