コード例 #1
0
        private RunInfo getItem(string assemblyName)
        {
            var info = new RunInfo(null);

            info.SetAssembly(assemblyName);
            return(info);
        }
コード例 #2
0
        public void SetUp()
        {
            _project = new Project(Path.GetFullPath("someProject.csproj"), new ProjectDocument(ProjectType.CSharp));
            _project.Value.SetOutputPath("");
            _project.Value.SetAssemblyName("someAssembly.dll");
            _bus                   = MockRepository.GenerateMock <IMessageBus>();
            _listGenerator         = MockRepository.GenerateMock <IGenerateBuildList>();
            _configuration         = MockRepository.GenerateMock <IConfiguration>();
            _buildRunner           = MockRepository.GenerateMock <IBuildRunner>();
            _testRunner            = MockRepository.GenerateMock <ITestRunner>();
            _testAssemblyValidator = MockRepository.GenerateMock <IDetermineIfAssemblyShouldBeTested>();
            _optimizer             = MockRepository.GenerateMock <IOptimizeBuildConfiguration>();
            _fs       = MockRepository.GenerateMock <IFileSystemService>();
            _cache    = MockRepository.GenerateMock <ICache>();
            _runCache = MockRepository.GenerateMock <IRunResultCache>();
            _runInfo  = new RunInfo(_project);
            _runInfo.ShouldBuild();
            _runInfo.SetAssembly(_project.Value.AssemblyName);
            _optimizer.Stub(o => o.AssembleBuildConfiguration(new string[] {})).IgnoreArguments().Return(new RunInfo[] { _runInfo });
            _preProcessor = MockRepository.GenerateMock <IPreProcessTestruns>();
            _preProcessor.Stub(x => x.PreProcess(null)).IgnoreArguments().Return(new PreProcessedTesRuns(null, new RunInfo[] { _runInfo }));
            var preProcessors     = new IPreProcessTestruns[] { _preProcessor };
            var buildPreProcessor = MockRepository.GenerateMock <IPreProcessBuildruns>();

            buildPreProcessor.Stub(x => x.PreProcess(null)).IgnoreArguments().Return(new RunInfo[] { _runInfo });
            var buildPreProcessors = new IPreProcessBuildruns[] { buildPreProcessor };

            _removedTestLocator = MockRepository.GenerateMock <ILocateRemovedTests>();
            _buildSessionRunner = new BuildSessionRunner(new BuildConfiguration(null), _cache, _bus, _configuration, _buildRunner, buildPreProcessors, _fs, _runCache);
            _consumer           = new ProjectChangeConsumer(_bus, _listGenerator, _configuration, _buildSessionRunner, new ITestRunner[] { _testRunner }, _testAssemblyValidator, _optimizer, preProcessors, _removedTestLocator);
        }
コード例 #3
0
        private RunInfo getRunInfo(Project x)
        {
            var info = new RunInfo(x);

            info.SetAssembly(x.GetAssembly(_configuration.CustomOutputPath));
            return(info);
        }
コード例 #4
0
        public void Should_run_cached_failed_and_ignored_tests_and_mark_for_rerun()
        {
            _resultCache.Stub(r => r.Failed).Return(new TestItem[] { new TestItem("assembly", "project", new TestResult(TestRunner.MSTest, TestRunStatus.Failed, "sometests")) });
            _resultCache.Stub(r => r.Ignored).Return(new TestItem[] { new TestItem("assembly", "project", new TestResult(TestRunner.NUnit, TestRunStatus.Ignored, "someignoredtests")) });
            var details = new RunInfo(new Project("project", new ProjectDocument(ProjectType.CSharp)));

            details.SetAssembly("assembly");

            _preProcessor.PreProcess(new PreProcessedTesRuns(null, new RunInfo[] { details }));
            details.GetTests().Length.ShouldEqual(2);
            details.GetTests()[0].Test.ShouldEqual("sometests");
            details.GetTests()[1].Test.ShouldEqual("someignoredtests");
            details.OnlyRunSpcifiedTestsFor(TestRunner.Any).ShouldBeTrue();
            details.RerunAllTestWhenFinishedFor(TestRunner.Any).ShouldBeTrue();
        }
コード例 #5
0
        public PreProcessedTesRuns PreProcess(PreProcessedTesRuns preProcessed)
        {
            // Clean up profiler logs before we start
            var logFiles = getProfilerOutput();

            cleanUpFiles(logFiles);

            var runMinimized = !(_isFullRun || minimizerIsDisabled() || _minimizerPaused);

            Logger.WriteDebug("Run minimized is " + runMinimized.ToString());
            if (runMinimized)
            {
                _bus.Publish(new RunInformationMessage(InformationType.PreProcessing, "", "", typeof(MinimizingPreProcessor)));
            }
            var finalDetails = new List <RunInfo>();
            var details      = preProcessed.RunInfos;

            if (!minimizerGraphsAndRiskIsOff())
            {
                try
                {
                    var assemblies = GetAssemblies();
                    //var hash = details.ToDictionary(current => current.Assembly);
                    if (!runMinimized || _runCount % 10 == 0)
                    {
                        _minimizer.LoadOldCachedFiles(assemblies);
                    }
                    _runCount++;
                    var tests = _minimizer.GetTestsFor(assemblies);
                    Logger.WriteDebug("minimizer returns " + tests.Count + " tests");

                    if (runMinimized)
                    {
                        var profiled = GetProfiledEntries();
                        Logger.WriteDebug("profiler returns " + profiled.Count() + " tests");
                        var all = Combine(tests, profiled);

                        //TODO THIS IS A HACK TO ENRICH PROFILED TESTS, REFACTOR ME
                        foreach (var t in all)
                        {
                            var original = t.TestAssembly
                                           .Replace(".mm.dll", ".dll")
                                           .Replace(".mm.exe", ".exe");
                            var testAssembly = original;
                            testAssembly = new PathTranslator(_configuration.WatchToken).TranslateFrom(testAssembly);
                            if (testAssembly == null)
                            {
                                testAssembly = original;
                            }
                            Logger.WriteDebug("Translated TestAssembly is: " + testAssembly + " original is: " + t.TestAssembly);
                            var current = details.FirstOrDefault(x => x.Assembly.Equals(testAssembly));
                            if (current == null)
                            {
                                current = finalDetails.FirstOrDefault(x => x.Assembly.Equals(testAssembly));
                                if (current == null)
                                {
                                    current = GetRunInfoFromAssembly(testAssembly);
                                }
                                if (current == null)
                                {
                                    throw new Exception("unable to match assembly for test. - assembly is " + testAssembly);
                                }
                                if (!finalDetails.Exists(x => x.Assembly.Equals(testAssembly)))
                                {
                                    finalDetails.Add(current);
                                }
                            }

                            foreach (var s in t.TestRunners)
                            {
                                var runner = ConvertStringToTestRunnerEnum(s);
                                var test   = getTestSignature(t, runner);
                                Logger.WriteDetails(string.Format("Adding test {0} to runner {1} on run info {2}", test,
                                                                  runner, current.Assembly));
                                current.AddTestsToRun(runner, test);
                            }
                        }

                        if (runMinimized)
                        {
                            addCurrentBrokenTests(details);
                        }

                        foreach (var detail in details)
                        {
                            detail.ShouldOnlyRunSpcifiedTestsFor(TestRunner.Any);
                        }
                        Logger.WritePreprocessor(string.Format("Found {0} affected tests", tests.Count));
                        _bus.Publish(new AssembliesMinimizedMessage());
                        finalDetails.AddRange(details);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteError(ex.ToString());
                    var newDetails = new List <RunInfo>();
                    foreach (var detail in details)
                    {
                        var newDetail = new RunInfo(detail.Project);
                        newDetail.SetAssembly(detail.Assembly);
                        if (detail.ShouldBeBuilt)
                        {
                            newDetail.ShouldBuild();
                        }
                        newDetails.Add(newDetail);
                    }
                }

                Logger.WriteDebug("Running 2nd generation garbage collection");
                GC.Collect(2);
                Logger.WriteDebug("Waiting for finalizers");
                GC.WaitForPendingFinalizers();
                Logger.WriteDebug("GC done");
            }

            Logger.WriteDebug("Getting profiler wrapper");
            _profilerWrapper = getProfilerWrapper();
            if (!runMinimized)
            {
                var wrapper = _profilerWrapper;
                _profilerWrapper = null;
                Logger.WriteDebug("Returning original runinfos");
                return(new PreProcessedTesRuns(wrapper, preProcessed.RunInfos)); // return original runInfos
            }
            finalDetails.ForEach(x => _runsToProfile.Add(x.CloneToTestRunInfo()));
            Logger.WriteDebug("Returning modified details");
            return(new PreProcessedTesRuns(_profilerWrapper, finalDetails.ToArray()));
        }