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

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)