Most of the times the Test cases need some pre-setup to be done before actually running the test steps under it. Pre-setup could be anything like deleting some records from database or applying some value to a variable in heading test step.
Most of the times we create a ‘Groovy Step’ for this purpose and code accordingly to do the pre-setup.
Its actually one way of doing. But SOAP UI provides us options like ‘Setup Script’ & ‘Teardown Script’.
These scripts do the set-up what is required before starting a Test Case and after completing that Test Case.
When we double click on any Test Case, we get the corresponding Test Case window which has all the test steps (if any) listed under it. The tabs Setup Script and Teardown Script will also be present there, these will do the job for you.
Inside Setup Script window we write the script that should be executed before running the actual test steps. As said, we can perform the delete operations on database tables or set some values to variables for the coming steps. Initially the setup srcipt is run and after its successful execution only the Test Case starts running the succeeding test steps.
Similarly Teardown Script, is executed after the successful execution of all the test steps of that Test Case. This could be useful in scenarios where one needs to do clean-up process of database (say, if developer wants to delete the records what he has inserted) or wants to delete some files which where written to file system as the by product of the application.
Employing this feature in the Test Suite, makes the developer more concentrate on test steps as Setup and Teardown Scripts are taking care of pre-setup and post-setup for running the Test Case.