This is a migrated thread and some comments may be shown as answers.

Any examples of Inital Set up / tear down of a test case

3 Answers 135 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Christopher
Top achievements
Rank 1
Christopher asked on 03 Feb 2014, 01:38 PM
Hi All

I have been reading through the documentation, and I was wondering if they were an example of a mix of code and recorded step where the test initially sets up the test data needed for the test, run's the recorded steps that have been created, then a coded step which tear down's the data used.

I know in other web automation tools you would have something let the following

public void initalSetup()
{
    // The set up would be here
}

public void test()
{
    // The test would be here
}


public void tearDown()
{
    // The tear down would be here
}

I know that this page exists http://docs.telerik.com/teststudio/user-guide/code-samples/general/execute-custom-scripts-before-after-test.aspx but I found it a bit confusing

Any help would be great

Thanks

Chris

3 Answers, 1 is accepted

Sort by
0
Velin Koychev
Telerik team
answered on 06 Feb 2014, 11:08 AM
Hello Chris,

Actually you are right that this article contains this information. Could you please elaborate more about what makes you confused in that article? We are always trying to keep our documentation as useful as possible and we appreciate your feedback. 

You should basically override the following two methods, in order to have initial Set up / tear down of a test case:
public override void OnAfterTestCompleted(TestResult result)
{
    // The set up would be here
}
 
public override void OnBeforeTestStarted()
{
    // The tear down would be here
}

What code you will use inside these two methods would be very specific to your test scenario.

Please let me know whether you have any additional questions.

Regards,
Velin Koychev
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Christopher
Top achievements
Rank 1
answered on 06 Feb 2014, 11:33 AM

Hi Velin

Thanks for getting back to me, what I found confusing was that they were no clear example (code example) of how a test was created, as per the structure I stated in my first post.

What I would like to achieve is something like the following

public override void OnAfterTestCompleted(TestResult result)
{   
   // The set up would be here
      I would like to add here an one or more sql scripts which would prepopulate my test data for the test into our databases, or have sql which removed test data from the database (if required)


public override void OnBeforeTestStarted()
{  
      // The tear down would be here

  I would like to add here an one or more sql scripts which would remove my test data for the test into our databases.
}

Further I have been looking for information about running a batch file from within Test Studio (i.e. as a coded step) would you know how this could be done.

Thanks

Chris

0
Accepted
Velin Koychev
Telerik team
answered on 11 Feb 2014, 02:22 PM
Hello Chris,

Thank you for the clarifications.

As I said before, what is inside these two methods is very specific to your application and test scenario. 

For example you can see this article from our documentation how to access SQL database with code. You can use put a similar code in these two methods.

 ...information about running a batch file from within Test Studio... 

You should be able to achieve this. For example you can see the solutions from this Stack Overflow link you can see several solutions. The most simple is using this line:

System.Diagnostics.Process.Start("c:\\batchfilename.bat");

I hope this helps.

Regards,
Velin Koychev
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Christopher
Top achievements
Rank 1
Answers by
Velin Koychev
Telerik team
Christopher
Top achievements
Rank 1
Share this question
or