How to work with MS Unit Test Assertion as step in Test Studio

Learn more about Test Studio here

More you meet people more questions you get. I love this part of my job, meeting and answering people queries. I usually talk to Test Professional who are doing manual testing. So some of their questions are very basic and this is expected because they are not coming from coding or programming background.

Recently in one of seminar I came across a question

How can I use MS Unit Test Assertion in a Test Step while automating test with Test Studio?

Answer of this questions is in three steps,

Step 1:

Add reference of Microsoft.VisualStudio.QualityTools.UnitTestFramework dll in Test Project

Step 2:

Create a coded step

Step 3:

Write Assertion in test

Add Reference

There are in two ways you can work on Test Studio. Either on Visual Studio plugin or on Test Studio standalone version.

Adding reference in Visual Studio is simpler. Right click on test project and from context menu select Add Reference. Browse to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll library and add reference in test project.

Even though you have added reference in Visual Studio make sure that you have added reference in test project opened in standalone version else you will get exception.

image

To add Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll assembly in Test Studio standalone version you need to follow following steps,

Select Project option in top menu

image

Click on Show Settings in project tab

clip_image001

On clicking on Show Settings you will get Project Settings dialog box. In dialog box click on Script Options. To add assembly reference click on Add Reference.

clip_image003

When you clock on Add Reference Test Studio will open File Chooser dialog box. In that browse Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll assembly reference location in file system and select that to add as reference in current Test project.

Create a coded step

To create Coded Step in select Test and from menu

image

You will find coded step added as below,

clip_image001[6]

Write Assertion in Test

Once Coded step is added you can write any assertion. To validate I am writing a very simple assertion as below,

You can view below code in Visual Studio,


[CodedStep(@"New Coded Step")]

 public void WebTest_CodedStep()
 {
 Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual("TestStudio", "TestStudio");

}

In Test Studio standalone version codes step will look like as following,

clip_image002

Now go ahead and execute test. You should able to get test passed successfully as given below,

clip_image003

I hope you find this post useful. To speedup automated testing do not forget to download trial of Test Studio from here

clip_image004

Advertisements

2 thoughts on “How to work with MS Unit Test Assertion as step in Test Studio

  1. Pingback: How to verify number of cookies while automating a test in Test Studio | Telerik Helper

  2. Pingback: How to work with NUnit Assertion as step in Test Studio | Telerik Helper

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s