This a behavior question of test runners
TestConext
is populated at run time of the "TestHarness/TestRunner".
Its is an abstract class that in Visual Studio
the process is called QAagent32.exe
that supplies an implemented version for this based upon what your test method and class requires of it, e.g. Iterating data rows from a Excel Worksheet
, TFS TestCase
parameter data table; Coded UI, Unit Test.
If you want to use what is already used in Visual Studio
you can just call GetType()
on it, and research from there for its fully qualified type used. However, IF that class type isn't available you'll have to implement a concrete class that fully implements TestContex
Then in code you can do like the following:
PlayBack.Initialize();
var yourTestClass = new YourUniqueClassTests();
yourTestClass.TestContext = TestConextFactory.GetImplimentation();
yourTestClass.TestMethodThatsImportant();
Now if your using the DataSource attribute on your test methods you will probably have to use reflection to pull that info.
var attribute= yourTestClass.GetType()
.GetMethod("TestMethodThatsImportant")
.GetCustomAttributes(typeof(DataSourceAttribute),false)[0]
as DataSourceAttribute;
This should be able to get that data for you. Once you have it you could add logic to decide on what type of TestContext
object you implement to set on the test class.