LeanFT C# Tutorial Part 6 – Parameterizing Tests

Since we are working with MSTest framework, we’ll have to deal with some of its limitations. One of them being that our test methods can not have parameters passed to them while being called(although there are indirect ways to do this but they are way too complicated). Lets focus on a simple approach that we can use:-

Our Visual Studio project has an app.config file which can be used to provide input data to our test methods. A sample config file in which i have added 2 custom keys looks like this:-


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <appSettings>
    <add key="username" value="leanft" />
    <add key="password" value="tutorial" />
 </appSettings>
</configuration>

Now if we have a test method which needs to use these keys, our c# code will look something like this:-


using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

[TestMethod]
public void login()
{
    string uName = ConfigurationManager.AppSettings["username"];
    string pWord = ConfigurationManager.AppSettings["password"];
    //do login here
}

This way we can parameterize our mstest test methods.

LeanFT C# Tutorial Part 7 – Using Insight Objects

Happy Automating !
Harshit Kohli

Advertisements

Eat, Sleep, Automate. REPEAT !

Tagged with: , , , , , ,
Posted in LeanFT
2 comments on “LeanFT C# Tutorial Part 6 – Parameterizing Tests
  1. […] Source: LeanF C# Tutorial Part 6 – Parameterizing Tests […]

  2. […] LeanFT Tutorial Part 6 – Parameterising Tests […]

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

Blog Stats
  • 168,130 hits
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 796 other followers

%d bloggers like this: