Run individual Test with Suite Setup

Jan 18, 2011 at 10:21 AM
Edited Jan 18, 2011 at 12:51 PM

Hi,

Is it possible to run an individual test but invoke the suite set up (if the test belongs to a suite). This should be optional as you may not want to run the setup depending on the actual test. The reason I ask is that when writing the tests it is much easier to run just that test rather than the entire suite, but if that test is dependant on the setup then it is not currently possible. This is also true if you have individual tests failing and need to apply the fix to pass these tests individually before running an entire suite.

EDIT - it does run the setup for any individual tests. I couldn't see this in the documentation though

Thanks

Jan 18, 2011 at 1:30 PM

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:
   - SQLTest_SETUP_SuiteX
   - SQLTest_SuiteX#TestA
   - SQLTest_SuiteX#TestB

If you run the test ”SQLTest_SuiteX#TestA” then the procedures will be run in this order:
   1. SQLTest_SETUP_SuiteX
   2. SQLTest_SuiteX#TestA

If you run the suite ”SuiteX” then the procedures will be run in this order:
   1. SQLTest_SETUP_SuiteX
   2. SQLTest_SuiteX#TestA
   3. SQLTest_SETUP_SuiteX
   4. SQLTest_SuiteX#TestB

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”.