private async Task ProcessCoverageSessionResults(ProjectInfo projectInfo, QueuedTest testQueueItem, string resultFilename, string fileToRead) { var sw = Stopwatch.StartNew(); _queries.RemoveFromQueue(testQueueItem); var coverageSession = new CoverageSession(); var testOutput = new resultType(); await Task.Run(() => { coverageSession = GetCoverageSessionFile(fileToRead); TestOutputFileReader testOutputFileReader = new TestOutputFileReader(); testOutput = testOutputFileReader.ReadTestResultFile(GetOutputFolder() + resultFilename); }); Log.DebugFormat("Coverage and Test Result Files Read Elapsed Time = {0}", sw.ElapsedMilliseconds); sw.Reset(); Log.DebugFormat("SaveUnitTestResults Elapsed Time = {0}", sw.ElapsedMilliseconds); sw.Reset(); await _queries.SaveCoverageSessionResults(coverageSession, testOutput, projectInfo, testQueueItem.IndividualTests); Log.DebugFormat("SaveCoverageSessionResults Elapsed Time = {0}", sw.ElapsedMilliseconds); Log.DebugFormat("ProcessCoverageSessionResults Completed, Name: {0}, Individual Test Count: {1}, Time from Build-to-Complete {2}", testQueueItem.ProjectName, testQueueItem.IndividualTests == null ? 0: testQueueItem.IndividualTests.Count(), DateTime.Now - testQueueItem.TestStartTime); System.IO.File.Delete(fileToRead); }
private async Task RunAllNunitTestsForProject(QueuedTest item) { Log.DebugFormat("Test Started TestRunId {0} on Project {1}", item.TestRunId, item.ProjectName); ProjectInfo projectInfo; if (item.IndividualTests == null || !item.IndividualTests.Any()) { projectInfo = _queries.GetProjectInfo(item.ProjectName); } else { projectInfo = _queries.GetProjectInfoFromTestProject(item.ProjectName); } if (item.Priority > 1) { BuildProject(_solutionDirectory + projectInfo.UniqueName); } if (projectInfo.TestProject != null) { Log.DebugFormat("Called GetProjectInfo for Project: {0}: .TestProject.AssemblyName:{1}", item.ProjectName, projectInfo.TestProject.AssemblyName); var fileNameGuid = Guid.NewGuid(); StringBuilder testParameters = GetTestParameters(item.ProjectName, item.IndividualTests, projectInfo, fileNameGuid); Log.DebugFormat("openCoverCommandLine: {0}", _openCoverCommandLine); Log.DebugFormat("Test Parameters: {0}", testParameters); await Task.Run(() => { RunNunitTests(_openCoverCommandLine, testParameters.ToString(), projectInfo, fileNameGuid, item); }); } else { Log.DebugFormat("GetProjectInfo returned a null TestProject for {0}", item.ProjectName); } Log.DebugFormat("Test Finished on Project {0} Elapsed Time {1}", item.ProjectName, DateTime.Now - item.TestStartTime); }
public void ProcessProjectTestQueueItem(QueuedTest queuedTest) { Log.DebugFormat("Ready to run another test from Project Test queue"); var projectInfo = _queries.GetProjectInfo(queuedTest.ProjectName); if (projectInfo.TestProject.Path == string.Empty) { // GetProjectOutputBuildFolder(); var projects = (Array)_dte.ActiveSolutionProjects; for (var i = 0; i < projects.Length; i++) { var project = (EnvDTE.Project)projects.GetValue(i); if (project.FullName == _solutionDirectory + projectInfo.TestProject.UniqueName) { projectInfo.TestProject.Path = GetProjectOutputBuildFolder(project); } } } //Build the Test project, because we don't know that it was built at the same time as the Code Project BuildProject(_solutionDirectory + projectInfo.TestProject.UniqueName); RunAllNunitTestsForProject(queuedTest); }
private async Task RunTests(string openCoverCommandLine, string arguments, ProjectInfo projectInfo, Guid fileNameGuid, QueuedTest testQueueItem) { // BuildProject(_solutionDirectory + testQueueItem.ProjectName); Log.DebugFormat("Verify project executing on Thread: {0}", System.Threading.Thread.CurrentThread.ManagedThreadId); var coverFilename = fileNameGuid.ToString() + "-cover.xml"; var resultFilename = fileNameGuid.ToString() + "-result.xml"; var startInfo = new System.Diagnostics.ProcessStartInfo { FileName = openCoverCommandLine, Arguments = arguments + coverFilename, RedirectStandardOutput = true, WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = false, CreateNoWindow = true }; Log.DebugFormat("ProcessStartInfo.Arguments: {0}", startInfo.Arguments.ToString()); Log.DebugFormat("ProcessStartInfo.FileName: {0}", startInfo.FileName.ToString()); var args = new string[] { @"-target:C:\USERS\LEE\APPDATA\LOCAL\MICROSOFT\VISUALSTUDIO\11.0EXP\EXTENSIONS\LEEM\TESTIFY\1.0\NUnit.Runners.2.6.2\nunit-console.exe ", @"-targetargs:C:\WIP\UnitTestExperiment\Domain.Test\bin\Debug\Domain.Test.dll /result:C:\Users\Lee\AppData\Local\Testify\UnitTestExperiment\5ce700cd-e242-46fd-b817-ff276495e958-result.xml /noshadow", @"-coverbytest:*.Test.dll", @"-hideskipped: Domain", @"-filter:+[MyProduct.Domain]* +[Domain.Test]*", @"-register:user" }; //var launcher = new OpenCoverLauncher(args); string stdout; try { // Start the process with the info we specified. // Call WaitForExit and then the using statement will close. using (System.Diagnostics.Process exeProcess = System.Diagnostics.Process.Start(startInfo)) { //long AffinityMask = (long)exeProcess.ProcessorAffinity; //AffinityMask = 0x0002; // use only the second processor, despite availability //exeProcess.ProcessorAffinity = (IntPtr)AffinityMask; if (testQueueItem.IndividualTests == null) { // lower the priority if running all tests for a project. exeProcess.PriorityClass = ProcessPriorityClass.BelowNormal; } stdout = exeProcess.StandardOutput.ReadToEnd(); await Task.Run(() => exeProcess.WaitForExit()); Log.DebugFormat("Results of Unit Test run: {0}", stdout); } } catch (Exception ex) { // Log error. Log.ErrorFormat("Error ocurred while RunTest for Project: {0}: Error:{1}", projectInfo.ProjectAssemblyName, ex.Message); } string fileToRead = GetOutputFolder() + coverFilename; await ProcessCoverageSessionResults(projectInfo, testQueueItem, resultFilename, fileToRead); }
private async Task RunNunitTests(string openCoverCommandLine, string arguments, ProjectInfo projectInfo, Guid fileNameGuid, QueuedTest testQueueItem) { await RunTests(openCoverCommandLine, arguments, projectInfo, fileNameGuid, testQueueItem); }