Category Archives: Unit Testing

Visual Studio Team System – Test Edition


Oh Yeah ! It was big gap between last post and this one.

May be I was looking for this snap !!



Continuing with my earlier posts I would like to write about two more tests available in visual studio

Ordered Tests

Web Tests

In previous post we saw various aspects of unit test and related features.

One of the key things to understand is while running the unit tests deployed for project in ordered manner is very important. This is required for building a scenario by running tests in specific sequence or this ordering might be important from a view that we have to run unit tests specific to certain section of our program.

How to Run Ordered Tests gives detailed insight on aspects related to ordered tests. This option for ordered test is available in developer edition as well as test edition.

Another important aspect related to testing of web based applications is web tests provided in visual studio test edition.

With help of web tests we can record various actions taken by user related to web application. This recorded actions include http request and responses, request status code time required for these requests.

Web Test Engine takes care of lots of things such as Extraction rules, validation rules, authentication, handling of cookies etc.

In addition to this features web tests can be connected to data sources like .csv files or excel files using the database providers so that post parameters covered in the recording can be connected to data for making these tests data driven.

Web tests play specific role to identify what changes have been made to UI or it can be used as a effective script tool which can easily populate the system to be deployed on client.

Two most important resources on web tests are

Amit Chatterjee’s Blog – A must read page for web tests

Working with web tests – MSDN page for web tests.

I hope this sounds interesting and useful to all of you.

Keep coming, keep reading ..


Unit Testing – Twists and Twirls ( Part 2)

@Kumbharlee Ghat

Let see some action now and jump into how to test simple function residing in a class.

For this we start with creating a simple class library in C# using Visual Studio 2008.


Lets proceed with putting some simple code snippet which provides us simple arithmetic operations.


Lets proceed with adding unit test project for this class library which will contain two unit test methods.

For this we right click on class name and click on choice “Create Unit Tests… “.


Following dialog is then displayed for user which allows some settings to be made as per user’s preferences.


Here we select class and both the methods inside class so that Unit Tests will be created for them.

Output project type is C# test project which user can select as per preference.

Additionally clicking “settings” button will open Test Generation Settings dialog which will allow to set Naming Settings as well as General settings.


There are five choices displayed for user under general settings.

  • Mark all test results inconclusive by default
  • Enable generation warnings
  • Globally Qualify all types
  • Enable documentation comments
  • Honor InternalsVisibleTo Attribute.

There you go ! Last one needs to be paid attention to ..

For time being lets proceed with our unit tests for AddTwoNumbers and SubTwoNumbers methods.

Once we click ok user is prompted for name of the Test project.


Clicking of Create button will add Test project to the solution.


If we closely observe few things added newly in the project

  • LocalTestRun.testrunconfig file
  • Unit Testing.vsmdi file
  • SimpleMathTest project which contains SimpleMathTest.cs file.

Lets see what all contents we have inside SimpleMathTest.cs file.


Object of TextContext class called testContextInstance.

get; set; for TextContext which provides information about and functionality for the current test run.

Next to this we have two test methods




we modify the values for “a” and “b” variables so as to check whether the actual and expected results match or not.

Changes made will look like this


What we re trying to judge here is after passing a as 10 and b as 10 , whether addition is returned as 20 and subtraction as 0.

But question remains.. How do I test this ?? Lets check it out…


As shown in the image, if we click on Test->Run we find two options

  • Test in current context
  • All Tests in solution

We select option Test in Current context. Another way to run Test in current context is Pressing Ctrl+R, T directly which will execute currently selected test case.

Another simplest way is to  click on vsmdi file which will open up Test List Editor listing all the test cases. We can also use toolbar items to run the tests in current context or all tests in solution.


After clicking on Run Test in current context what we get is as follows


What we see here in bottom as test is passed. Since we passed 10,10 as two input values and 20 as expected result; both values matched and test case is marked as successful(passed).

Whether to check what happens when actual and expected values do not match lets try out changing the values and this time we do it in SubTwoNumbersTest.

We change the value of b as 20 but still expected result is 0 and this is not going to match with actual value.

This time we will run the test case by using option ctrl+R, T

The failed test case result will look like


We can also add columns to Test Results by right clicking first column header as per our preference.


So far we have used Asser.Equal to compare actual and expected result. But Assert class provides us various methods which can be used to  conduct a test case. All the details for this methods can be found here.

Before we conclude lets quickly summarize what we have seen in this post

  1. How to add a unit test project
  2. Details of unit test project and how test functions are added.
  3. How to run test cases and ways to run test cases
  4. Details of  Assert class and methods residing under it

In coming post we will see how “Honor Internals Visible To “ attribute is used and what happens with methods with different scope like private, internal and private static etc.

Please do write me about your feedback or queries  which I am expecting the most , so that this articles can be made better and better !

Unit Testing – Twists and Twirls


In my previous posts , we saw some of the interesting scenarios in Interoperability. Having covered this area lets check out some of the “must know “ aspects and areas under Unit Testing.

Frequently Used Terminologies

Test Driven Development :

Test-driven development (TDD) is an advanced technique of using automated unit tests to drive the design of software and force decoupling of dependencies. The result of using this practice is a comprehensive suite of unit tests that can be run at any time to provide feedback that the software is still working. This technique is heavily emphasized by those using Agile development methodologies.

click here for detailed information.

Unit Testing:

The primary goal of unit testing is to take the smallest piece of testable software in the application, isolate it from the remainder of the code, and determine whether it behaves exactly as you expect. Each unit is tested separately before integrating them into modules to test the interfaces between modules. Unit testing has proven its value in that a large percentage of defects are identified during its use.

The most common approach to unit testing requires drivers and stubs to be written. The driver simulates a calling unit and the stub simulates a called unit. The investment of developer time in this activity sometimes results in demoting unit testing to a lower level of priority and that is almost always a mistake. Even though the drivers and stubs cost time and money, unit testing provides some undeniable advantages. It allows for automation of the testing process, reduces difficulties of discovering errors contained in more complex pieces of the application, and test coverage is often enhanced because attention is given to each unit.

MSDN info gives detailed insight on this.

Test Scenarios:

Test scenarios represent a powerful tool for test development. In general scenario defines an own model of target system, called the testing model. Scenario must define the state class for this model and the transitions, which must be described in terms of target methods

Test Cases:

A test case in software engineering is a set of conditions or variables under which a tester will determine whether an application or software system is working correctly or not. The mechanism for determining whether a software program or system has passed or failed such a test is known as a test oracle. In some settings, an oracle could be a requirement or use case, while in others it could be a heuristic. It may take many test cases to determine that a software program or system is functioning correctly. Test cases are often referred to as test scripts, particularly when written. Written test cases are usually collected into test suites.

More info on this Wiki page.

Code Coverage:

Code coverage is a measure used in software testing. It describes the degree to which the source code of a program has been tested. It is a form of testing that inspects the code directly and is therefore a form of white box testing. In time, the use of code coverage has been extended to the field of digital hardware, the contemporary design methodology of which relies on hardware description language(HDLs).

Code coverage techniques were amongst the first techniques invented for systematic software testing.

Detailed info is here.

Test Frameworks:

Unit testing frameworks, which help simplify the process of unit testing, have been developed for a wide variety of languages as detailed in this list of unit testing frameworks. It is generally possible to perform unit testing without the support of specific framework by writing client code that exercises the units under test and uses assertions, exception handling or other control flow mechanisms to signal failure. This approach is valuable in that there is a barrier to entry for the adoption of unit testing; having scant unit tests is hardly better than having none at all, whereas once a framework is in place, adding unit tests becomes relatively easy.

Detailed list of unit testing framework is worth having look at.

Okay ! Enough of theory .. isn’t it ??

We talked about Twists and Twirls .. where are they ???

We will be coming across them from next post as we go ahead and see the actual examples.  Getting used to this terminologies is really important and we will need them as we see various aspects of Unit Testing.

Till then .. Have a Nice One 🙂