public async Task <bool> ExecuteTests() { try { var log = _outputLogger.GetLogFromOutput(TestsExecutionOutput, string.Empty); var document = MutationDocumentManagerService.CreateDocument(nameof(CommandPromptOutputViewer), log); var test = new TestExecutor(Settings, _source.TestClaz.ClassLibrary); document.Title = TestsExecutionOutput; if (!_silently) { document.Show(); } void OutputData(object sender, string args) => log.CommandPromptOutput += args.Encode().PrintWithPreTag(); test.EnableCustomOptions = ChkEnableCodeCoverage.IsChecked; test.EnableLogging = false; test.OutputDataReceived += OutputData; test.X64TargetPlatform = _source.X64TargetPlatform; test.FullyQualifiedName = _source.TestClaz.MethodDetails.Count > Convert.ToInt32(Settings.UseClassFilterTestsThreshold) || ChkUseClassFilter.IsChecked || _source.TestClaz.BaseClass != null ? _source.TestClaz.Claz.Syntax.FullName() : string.Empty; if (_silently) { test.FullyQualifiedName = _source.TestClaz.Claz.Syntax.FullName(); } await test.ExecuteTests(_source.TestClaz.MethodDetails); var coverageAnalyzer = new CoverageAnalyzer(); coverageAnalyzer.FindCoverage(_source, test.CodeCoverage); if (test.LastTestExecutionStatus == TestExecutionStatus.Success) { if (!_silently) { document.Close(); } return(true); } } catch (Exception exp) { Trace.TraceError("Tests Execution Failed [{0}]", exp); MessageBoxService.Show(exp.Message); } return(false); }
public void PrintReport() { if (_mutationProcessLog == null || string.IsNullOrWhiteSpace(_mutationProcessLog.ToString())) { MessageBoxService.Show("No any Report Exist"); return; } _printDocument = MutationDocumentManagerService.CreateDocument( nameof(CommandPromptOutputViewer), _outputLogger.GetLogFromOutput($"{_source.Claz.Syntax.ClassName()}_Dynamic_Mutation_Analysis", _mutationProcessLog.ToString())); _printDocument.Show(); }
private async Task <bool> ExecuteBuild() { try { var buildLog = _outputLogger.GetLogFromOutput(MSBuildOutput, string.Empty); var document = MutationDocumentManagerService.CreateDocument(nameof(CommandPromptOutputViewer), buildLog); document.Title = MSBuildOutput; document.Show(); buildLog.CommandPromptOutput += "Building Test Project...".PrintWithPreTag(); void OutputData(object sender, string args) => buildLog.CommandPromptOutput += args.Encode().PrintWithPreTag(); var testCodeBuild = new BuildExecutor(Settings, _source.TestClaz.ClassProject) { BaseAddress = Settings.ServiceAddress, EnableLogging = ChkEnableDiagnostic.IsChecked, QuietWithSymbols = true }; testCodeBuild.OutputDataReceived += OutputData; if (_source.BuildInReleaseMode) { await testCodeBuild.ExecuteBuildInReleaseModeWithoutDependencies(); } else { await testCodeBuild.ExecuteBuildInDebugModeWithoutDependencies(); } testCodeBuild.OutputDataReceived -= OutputData; if (testCodeBuild.LastBuildStatus != BuildExecutionStatus.Failed) { document.Close(); } else { MessageBoxService.Show("\nTest Project Build is failed!"); } return(testCodeBuild.LastBuildStatus == BuildExecutionStatus.Success); } catch (Exception e) { MessageBoxService.Show(e.Message); Trace.TraceError("Unknown Exception Occurred On Test Project Build {0}", e); return(false); } }
public async Task BtnApplyMutantsClick() { _numberOfMutantsExecutingInParallel = Convert.ToByte(NumberOfMutantsExecutedInParallel); if (SelectedMutants.All(x => x.Level != MutantLevel.Mutant)) { if (!_silently) { MessageBoxService.Show("Click Find Mutants Or Select At Least One Mutant"); } return; } try { await InitializeMutants((ObservableCollection <object>) _selectedMutators); IsSplashScreenShown = true; if (ChkEnableDiagnostic.IsChecked) { _testDiagnosticDocument = MutationDocumentManagerService.CreateDocument( nameof(CommandPromptOutputViewer), _testDiagnosticDocumentViewModel); _buildDiagnosticDocument = MutationDocumentManagerService.CreateDocument( nameof(CommandPromptOutputViewer), _buildDiagnosticDocumentViewModel); _testDiagnosticDocument.Show(); _buildDiagnosticDocument.Show(); } MutantOperationsEnabled = false; ProgressBarMutationVisible = Visibility.Visible; MinimumProgress = 0; CurrentProgress = 0; var stopWatch = new Stopwatch(); stopWatch.Start(); _mutationProcessLog = new StringBuilder(); if (!_source.MethodDetails.SelectMany(x => x.Mutants).Any()) { if (!_silently) { MessageBoxService.Show(MutantsNotExist); } return; } var selectedMutants = SelectedMutants.Where(x => x.Level == MutantLevel.Mutant).ToList(); foreach (var mutant in _source.MethodDetails.SelectMany(x => x.Mutants)) { if (selectedMutants.All(x => x.MutantId != mutant.Id && mutant.ResultStatus == MutantStatus.NotRun)) { mutant.ResultStatus = MutantStatus.Skipped; } } _directoryFactory.BuildExtensions = BuildExtensions; _directoryFactory.NumberOfMutantsExecutingInParallel = _numberOfMutantsExecutingInParallel; _directoryFactory.DeleteDirectories(); await _directoryFactory.PrepareDirectoriesAndFiles(); var methodDetails = _source.MethodDetails.Where(x => x.TestMethods.Any()).ToList(); MaximumProgress = methodDetails.SelectMany(x => x.NotRunMutants).Count(); if (!methodDetails.Any()) { if (!_silently) { MessageBoxService.Show(NoAnyTestsExist); } return; } IsSplashScreenShown = false; _mutantExecutor = new MutantExecutor(_source, Settings) { EnableDiagnostics = ChkEnableDiagnostic.IsChecked, NumberOfMutantsExecutingInParallel = _numberOfMutantsExecutingInParallel, UseClassFilter = ChkUseClassFilter.IsChecked || _source.TestClaz.MethodDetails.Count > Convert.ToInt32(Settings.UseClassFilterTestsThreshold) || _source.TestClaz.BaseClass != null, BaseAddress = Settings.ServiceAddress }; if (_silently) { _mutantExecutor.UseClassFilter = true; } _testDiagnosticDocumentViewModel.CommandPromptOutput = HtmlTemplate; _buildDiagnosticDocumentViewModel.CommandPromptOutput = HtmlTemplate; void MutantExecutorOnMutantExecuted(object sender, MutantEventArgs e) { if (ChkEnableDiagnostic.IsChecked) { _testDiagnosticDocumentViewModel.CommandPromptOutput += e.TestLog; _buildDiagnosticDocumentViewModel.CommandPromptOutput += e.BuildLog; } CurrentProgress++; } _mutantExecutor.MutantExecuted += MutantExecutorOnMutantExecuted; await _mutantExecutor.ExecuteMutants(); _mutationProcessLog.Append(_mutantExecutor.LastExecutionOutput); _mutantExecutor.MutantExecuted -= MutantExecutorOnMutantExecuted; if (!_silently && ChkAnalyzeExternalCoverage.IsChecked && _source.ExternalCoveredClassesIncluded.Any()) { const string title = "Analyzing External Coverage"; var externalCoverageLog = _outputLogger.GetLogFromOutput(title, string.Empty); externalCoverageLog.CommandPromptOutput = HtmlTemplate; var chalkHtml = new ChalkHtml(); void OutputDataReceived(object sender, string output) => externalCoverageLog.CommandPromptOutput += output; chalkHtml.OutputDataReceived += OutputDataReceived; var mutantAnalyzer = new MutantAnalyzer(chalkHtml, Settings) { BuildInReleaseMode = _source.BuildInReleaseMode, ConcurrentTestRunners = _numberOfMutantsExecutingInParallel, EnableDiagnostics = ChkEnableDiagnostic.IsChecked, ExecuteAllTests = ChkExecuteAllTests.IsChecked, IncludeNestedClasses = _source.IncludeNestedClasses, IncludePartialClasses = _source.TestClaz.PartialClassNodesAdded, SourceProjectLibrary = _source.ClassLibrary, SurvivedThreshold = 0.01, TestClass = _source.TestClaz.FilePath, TestProject = _source.TestClaz.ClassProject, TestProjectLibrary = _source.TestClaz.ClassLibrary, UseClassFilter = ChkUseClassFilter.IsChecked, X64TargetPlatform = _source.X64TargetPlatform, UseExternalCodeCoverage = true, ProgressIndicator = '*', MutantsPerLine = Convert.ToInt32(MutantsPerLine) }; var document = MutationDocumentManagerService.CreateDocument(nameof(CommandPromptOutputViewer), externalCoverageLog); document.Title = title; document.Show(); foreach (var acc in _source.ExternalCoveredClassesIncluded) { mutantAnalyzer.ExternalCoveredMutants.AddRange(acc.MutantsLines); var projectFile = new FileInfo(acc.ClassPath).FindProjectFile(); mutantAnalyzer.SourceProjectLibrary = projectFile.FindLibraryPath()?.FullName; if (!string.IsNullOrWhiteSpace(mutantAnalyzer.SourceProjectLibrary)) { var accClass = await mutantAnalyzer.Analyze( acc.ClassPath, acc.ClassName, projectFile.FullName); accClass.CalculateMutationScore(); if (accClass.MutationScore.Survived == 0) { acc.ZeroSurvivedMutants = true; } } } chalkHtml.OutputDataReceived -= OutputDataReceived; mutantAnalyzer.ExternalCoveredMutants.Clear(); } stopWatch.Stop(); _mutantExecutor.PrintMutatorSummary(_mutationProcessLog); _mutantExecutor.PrintClassSummary(_mutationProcessLog); _mutationProcessLog.AppendLine("<fieldset style=\"margin-bottom:10; margin-top:10;\">"); _mutationProcessLog.AppendLine("Execution Time: ".PrintImportantWithLegend()); _mutationProcessLog.Append($"{stopWatch.Elapsed}".PrintWithPreTagWithMarginImportant()); _mutationProcessLog.AppendLine("</fieldset>"); _previousMutants.Clear(); foreach (var mutant in _source.MethodDetails.SelectMany(x => x.Mutants)) { var key = $"{mutant.Mutation.Location} - {mutant.Mutation.DisplayName}"; if (!_previousMutants.ContainsKey(key)) { _previousMutants.Add(key, mutant.ResultStatus); } } PrintMutants(); RunFileWatcherService(); } catch (Exception exception) { Trace.TraceError("Unknown Exception Occurred by Mutation Analyzer {0}", exception.StackTrace); MessageBoxService.Show(exception.Message); } finally { MutantOperationsEnabled = true; IsSplashScreenShown = false; ProgressBarMutationVisible = Visibility.Hidden; _directoryFactory.DeleteDirectories(); _idle = true; _silently = false; var notification = NotificationService.CreatePredefinedNotification(MutationIsCompletedNotification, string.Empty, string.Empty); await notification.ShowAsync(); } }