public async Task <ITestsExecutionResult <TTestCase> > ProcessTests(IList <TTestCase> impactedTests, StructuralDelta <TestsModel <TTestCase>, TTestCase> testsDelta, TProgramDelta programDelta,
                                                                            CancellationToken cancellationToken)
        {
            using (instrumentor)
            {
                applicationClosedHandler.AddApplicationClosedListener(instrumentor);

                await instrumentor.Instrument(programDelta.NewModel, impactedTests, cancellationToken);

                executor.TestResultAvailable += TestResultAvailable;
                var result = await executor.ProcessTests(impactedTests, testsDelta, programDelta, cancellationToken);

                executor.TestResultAvailable -= TestResultAvailable;

                CorrespondenceLinks coverage = instrumentor.GetCorrespondenceLinks();

                var failedTests = result.TestcasesResults.Where(x => x.Outcome == TestExecutionOutcome.Failed).Select(x => x.TestCase.Id).ToList();

                var coveredTests         = coverage.Links.Select(x => x.Item1).Distinct().ToList();
                var testsWithoutCoverage = impactedTests.Where(x => !coveredTests.Contains(x.Id)).Select(x => x.Id).ToList();

                testsWithoutCoverage.ForEach(x => loggingHelper.WriteMessage("Not covered: " + x));
                failedTests.ForEach(x => loggingHelper.WriteMessage("Failed Tests: " + x));

                testsWithoutCoverage.Except(failedTests).ForEach(x => loggingHelper.WriteMessage("Not covered and not failed Tests: " + x));

                correspondenceModelManager.UpdateCorrespondenceModel(coverage, programDelta, testsDelta, failedTests);

                applicationClosedHandler.RemovedApplicationClosedListener(instrumentor);
                return(result);
            }
        }
        public virtual async Task <TResult> ExecuteRTSRun(TProgramDelta programDelta, CancellationToken token)
        {
            var testsDelta = await loggingHelper.ReportNeededTime(() => testsDeltaAdapter.GetTestsDelta(programDelta, FilterFunction, token), "Tests Discovery");

            token.ThrowIfCancellationRequested();

            await loggingHelper.ReportNeededTime(() => testSelector.SelectTests(testsDelta, programDelta, token), "Tests Selection");

            var impactedTests = testSelector.SelectedTests;

            foreach (var impactedTest in impactedTests)
            {
                token.ThrowIfCancellationRequested();
                ImpactedTest?.Invoke(this, new ImpactedTestEventArgs <TTestCase>(impactedTest,
                                                                                 responsibleChangesReporter.GetResponsibleChanges(testSelector.CorrespondenceModel, impactedTest, programDelta)));
            }

            loggingHelper.WriteMessage($"{impactedTests.Count} Tests impacted");

            var prioritizedTests = await loggingHelper.ReportNeededTime(() => testPrioritizer.PrioritizeTests(impactedTests, token), "Tests Prioritization");

            TestsPrioritized?.Invoke(this, new TestsPrioritizedEventArgs <TTestCase>(prioritizedTests));

            var executor = testProcessor as ITestExecutor <TTestCase, TProgramDelta, TProgram>;

            if (executor != null)
            {
                executor.TestResultAvailable += TestResultAvailable;
            }
            var processingResult = await loggingHelper.ReportNeededTime(() => testProcessor.ProcessTests(prioritizedTests, testsDelta, programDelta, token), "Tests Processing");

            if (executor != null)
            {
                executor.TestResultAvailable -= TestResultAvailable;
            }

            return(processingResult);
        }
Exemplo n.º 3
0
        private void InstrumentTestAssembly(string testAssembly, CancellationToken cancellationToken)
        {
            if (!File.Exists(testAssembly))
            {
                loggingHelper.WriteMessage($"Warning: {testAssembly} does not exist!");
                return;
            }

            using (var moduleDefinition = LoadModule(testAssembly))
            {
                if (AlreadInstrumented(moduleDefinition))
                {
                    return;
                }

                ModuleDefinition msTestModule = null;

                foreach (var type in moduleDefinition.GetTypes())
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    if (type.Name == MonoModuleTyp)
                    {
                        continue;
                    }

                    InstrumentType(type);

                    if (type.HasMethods)
                    {
                        //Roslyn uses '+' for nested classes, Mono '/'
                        if (!type.Methods.Any(x => msTestTestcases.Any(y => y.Id == $"{type.FullName.Replace('/', '+')}.{x.Name}")))
                        {
                            continue;
                        }

                        if (msTestModule == null)
                        {
                            msTestModule = GetMsTestModule(moduleDefinition);
                        }

                        var testInitMethod    = InsertMethodWithAttributeIfNotExists(type, TestInitName, msTestModule, MSTestConstants.MsTestTestInitializeAttributeFullName);
                        var testCleanupMethod = InsertMethodWithAttributeIfNotExists(type, TestCleanupName, msTestModule, MSTestConstants.MsTestTestCleanupAttributeFullName);

                        InsertCallToDependencyMonitorBeginning(testInitMethod, testMethodStartedReference);
                        InsertCallToDependencyMonitorEnd(testCleanupMethod, testMethodEndReference);

                        foreach (var method in type.Methods)
                        {
                            cancellationToken.ThrowIfCancellationRequested();
                            var id = $"{type.FullName}.{method.Name}";
                            if (msTestTestcases.Any(x => x.Id == id))
                            {
                                string methodArgument = testNamesToExecutionIds.Single(x => x.Item1 == id).Item2.ToString();
                                InsertCallToDependencyMonitorBeginning(method, testMethodNameReference, methodArgument, type.FullName);
                            }
                        }
                    }
                }

                UpdateModule(moduleDefinition);
            }
        }