VS Team: A concrete example of the use of the TestContext property using Microsoft Unit Testing Framework?

735 Views Asked by At

While writing my tests this week for a new project, I encountered the TestContext property using the Microsoft Unit Testing Framework available with Visual Studio Team System.

I was wondering:

1. How this property could be used concretely?

2. In other words, what is its purpose?

3. Anyone has a concrete example to provide to ease my understanding?

I have written many tests so far in my career, and have never ever found a use for this particular property.

Any clue anyone?

Thanks in advance! =)

1

There are 1 best solutions below

1
On BEST ANSWER

This property can be used to run parametrized tests, like if you have constants you don't want to hardcode in your test project that you want to load and share among all the tests. By default it will be populated with useful information, like the path where your test is running.

Then it is one of the key to run the same test several times with different values. The MSTest framework can be used to link your test project to a database or a csv file and run the tests once for all the rows in the said DB. This is called data driven testing and you'll find many sample on the net. Here is one how to.