Sample 2: Linking with Code Coverage Profiler and Running the Tests
The following sample shows how to run a test is run with NCover:
1. The license is checked.
2. The GetCoverageTools() method prints all available profilers on the machine. When the GetCoverageTools() method has a false argument, the method will return a list of all the profilers with which Typemock Isolator can be linked.
3. The code unlinks any previous profiler that was linked with Typemock Isolator.
4. The static TypeMockProcess.Start() method runs the tests.
C# public void RunTest(string profilerName) { if(!Service.HasLicenseToLink()) { Console.WriteLine("In order to link Typemock Isolator you need a valid licence"); return; } Console.WriteLine("Availble profilers on this machine:"); foreach(string profiler in Service.GetCoverageTools(true)) { Console.WriteLine(profiler); } //First unlink Typemock Isoaltor with any previous profiler TypeMockProcess.UnlinkWithCovarage(); //Set the process to run and its command line arguments ProcessStartInfo info = new ProcessStartInfo(UnitTestRunner, UnitTestRunnerParams); //Run the process with TypeMockEnabled and link with profiler using(TypeMockProcess.Start(info, profilerName)) {} }
When you are debugging code that uses TypeMockProcess,
remember to disable Typemock Isolator from the MS Visual Studio's Tools menu. If
Typemock Isolator is enabled, any process that you create will be enabled
as well. This will not represent a real-life situation when the
application is running outside of MS Visual Studio.