Adil Akhter

on software engineering

More on Unit Testing : TestContext

From empirical evidence, we know that improving code coverage by verifying all the boundary conditions, and ensuring quality of code-base significantly enhances maintainability and comprehensibility of complex software systems. Therefore, writing effective unit and integration tests has become one of the integral part in software development life cycle. In fact, development methodology such as TDD has been embraced rapidly due to these realized benefits. In today's post, we talk more about TestContext of mstest. In particular, we focus on its usage in devising effective unit tests. Before moving forward, we would like to outline the previous posts of the series regarding Unit Testing.

What is TestContext?

TestContext is an abstract class of Microsoft.VisualStudio.TestTools.UnitTesting namespace. It exposed several properties related to the current context (i.e., current test run). In addition, it provides following supports: (read more)

Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# May 4, 2008 6:51 AM

More on Unit Testing : TestContext « Adil Akhter’s Weblog said:

Pingback from  More on Unit Testing : TestContext « Adil Akhter’s Weblog

# May 4, 2008 9:59 AM

TestContext - more on VSTS unit testing « Adil Akhter’s Weblog said:

Pingback from  TestContext - more on VSTS unit testing « Adil Akhter’s Weblog

# May 4, 2008 12:29 PM

iq test said:

Pingback from  iq test

# May 5, 2008 5:47 PM

asp net developer said:

Pingback from  asp net developer

# May 12, 2008 3:45 AM

net developer said:

Pingback from  net developer

# May 14, 2008 6:09 PM

Dave's Team System Blog said:

If you're using Windows Server 2008 and UAC, you may have had some difficulty getting the code coverage

# September 29, 2008 2:10 PM

Muhammad Iqbal Marath said:

i think it best article for those who r going to start wrtiting unit testing.

# July 15, 2010 3:47 AM

Jennifer S said:

Thanks for demonstrating more about how to use TestContext than MSDN examples.  This is helpful for me as I'm transitioning from nUnit to MS Test.

# January 13, 2011 8:36 AM

Andrey Bushman said:

Thank you very much!

# October 4, 2012 3:47 AM

Philip said:

Where is your private TestContext object being assigned to? None of the code in the article shows this and so all your tests will fail because TestContext will always be null in your UserManagerTests class.

# November 15, 2012 3:26 AM

Adil Akhter said:

Philip,

Thanks for your comment. I will update this post with the clarification on how the TestContext gets initialized.

This is what happens:

"When you run a unit test, you are automatically provided with a concrete instance of the TestContext type, if the test class that contains your unit test method has a TestContext property defined. This means that you do not have to instantiate or derive the TestContext type in your code"  [1].

Reference:

[1] msdn.microsoft.com/.../ms404699(v=vs.80).aspx

# November 15, 2012 10:16 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)