// ------------------------------------------------------ /// <summary> /// Creates the test runner source file for the current startup /// project and adds it to the project. /// </summary> /// <param name="doNotRunTests"> /// If true, the file will be generated but will not include any /// statements to run any tests. If false, the tests will be run /// based on the current selection in the CxxTest Suites view. /// </param> public void CreateTestRunnerFile(bool doNotRunTests) { TestSuiteCollection suites = AllTestSuites; Dictionary <string, bool> testsToRun; if (doNotRunTests) { testsToRun = null; } else { testsToRun = TryToGetTestsToRun(); } HierarchyItem startupProject = VsShellUtils.GetStartupProject(this); string projectDir = startupProject.ProjectDirectory; string workingDir = GetActiveWorkingDirectory(startupProject); Project project = startupProject.GetExtObjectAs <Project>(); string runnerPath = Path.Combine( projectDir, Constants.TestRunnerFilename); // Remove the file from the project if necessary, and delete it // from the file system if it exists. VCProject vcproj = (VCProject)project.Object; if (!vcproj.CanAddFile(runnerPath)) { IVCCollection coll = (IVCCollection)vcproj.Files; vcproj.RemoveFile(coll.Item(Constants.TestRunnerFilename)); } if (File.Exists(runnerPath)) { File.Delete(runnerPath); } TestRunnerGenerator generator = new TestRunnerGenerator(runnerPath, suites, testsToRun); generator.Generate(); // Add the file to the project. vcproj.AddFile(runnerPath); }
// ------------------------------------------------------ /// <summary> /// Launches the tests for the solution. /// </summary> public void LaunchTests() { HierarchyItem startupProject = VsShellUtils.GetStartupProject(this); lastRunProject = startupProject; if (startupProject == null) { return; } TryToSetTestResultsText("Running the tests..."); debuggerEvents.StartingTestRun = true; uint flags = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd; string projectDir = startupProject.ProjectDirectory; string workingDir = GetActiveWorkingDirectory(startupProject); string exePath = GetActiveExecutablePath(startupProject); Guid guidNativeOnlyEng = new Guid("3B476D35-A401-11D2-AAD4-00C04F990171"); VsDebugTargetInfo debugTarget = new VsDebugTargetInfo(); debugTarget.bstrExe = exePath; debugTarget.bstrCurDir = workingDir; debugTarget.fSendStdoutToOutputWindow = 1; debugTarget.grfLaunch = flags; debugTarget.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; debugTarget.clsidCustom = guidNativeOnlyEng; VsShellUtilities.LaunchDebugger(this, debugTarget); }