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" ?>
    <add key="username" value="leanft" />
    <add key="password" value="tutorial" />

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;

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


2 replies »

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