Ejemplo n.º 1
0
        public void MergeDotCoverSnapshots()
        {
            var DotCoverSnapshots = Directory.GetFiles(MergeDotCoverSnapshotsInDirectory, "*.dcvr", SearchOption.AllDirectories).ToList();

            if (string.IsNullOrEmpty(JobName))
            {
                JobName = "DotCover";
            }
            var MergedSnapshotFileName = JobName.Split(',')[0];

            MergedSnapshotFileName = "Merged " + MergedSnapshotFileName + " Snapshots";
            TestCoverageMerger.MergeCoverageSnapshots(DotCoverSnapshots, MergeDotCoverSnapshotsInDirectory + "\\" + MergedSnapshotFileName, MergeDotCoverSnapshotsInDirectory + "\\DotCover", DotCoverPath);
        }
Ejemplo n.º 2
0
        public void RunTestJobs(string jobName = "")
        {
            if (jobName != "")
            {
                JobName = jobName;
            }

            // Unpack jobs
            var JobNames         = new List <string>();
            var JobAssemblySpecs = new List <string>();
            var JobCategories    = new List <string>();

            if (!string.IsNullOrEmpty(JobName) && string.IsNullOrEmpty(MergeDotCoverSnapshotsInDirectory))
            {
                foreach (var Job in JobName.Split(','))
                {
                    var TrimJobName = Job.TrimEnd('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ' ');
                    if (JobSpecs.ContainsKey(TrimJobName))
                    {
                        JobNames.Add(TrimJobName);
                        if (JobSpecs[TrimJobName].Item2 == null)
                        {
                            JobAssemblySpecs.Add(JobSpecs[TrimJobName].Item1);
                            JobCategories.Add("");
                        }
                        else
                        {
                            JobAssemblySpecs.Add(JobSpecs[Job].Item1);
                            JobCategories.Add(JobSpecs[Job].Item2);
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Unrecognized Job {Job} was ignored from the run");
                    }
                }
            }
            if (!string.IsNullOrEmpty(ProjectName))
            {
                JobNames.Add(ProjectName);
                JobAssemblySpecs.Add(ProjectName);
                if (!string.IsNullOrEmpty(Category))
                {
                    JobCategories.Add(Category);
                }
                else
                {
                    JobCategories.Add("");
                }
            }
            if (!File.Exists(TestRunner.Path))
            {
                throw new ArgumentException("Error cannot find VSTest.console.exe or MSTest.exe. Use either --VSTestPath or --MSTestPath parameters to pass paths to one of those files.");
            }

            if (ApplyDotCover && DotCoverPath != "" && !(File.Exists(DotCoverPath)))
            {
                throw new ArgumentException("Error cannot find dotcover.exe. Use --DotCoverPath parameter to pass a path to that file.");
            }

            if (!string.IsNullOrEmpty(DoServerStart) || !string.IsNullOrEmpty(DoStudioStart))
            {
                InstallServer();
            }

            TestRunner.ReadPlaylist();

            for (var i = 0; i < JobNames.Count; i++)
            {
                var ThisJobName               = JobNames[i].ToString();
                var ProjectSpec               = JobAssemblySpecs[i].ToString();
                var TestCategories            = JobCategories[i].ToString();
                var TestAssembliesList        = "";
                var TestAssembliesDirectories = new List <string>();
                if (!TestRunner.TestsPath.EndsWith("\\"))
                {
                    TestRunner.TestsPath += "\\";
                }
                foreach (var Project in ProjectSpec.Split(','))
                {
                    Tuple <string, List <string> > UnPackTestAssembliesListAndDirectories = ResolveTestAssemblyFileSpecs(TestRunner.TestsPath + Project + ".dll");
                    TestAssembliesList += UnPackTestAssembliesListAndDirectories.Item1;
                    if (UnPackTestAssembliesListAndDirectories.Item2.Count > 0)
                    {
                        TestAssembliesDirectories = TestAssembliesDirectories.Concat(UnPackTestAssembliesListAndDirectories.Item2).ToList();
                    }
                    if (TestAssembliesList == "")
                    {
                        UnPackTestAssembliesListAndDirectories = ResolveProjectFolderSpecs(TestRunner.TestsPath + Project);
                        TestAssembliesList += UnPackTestAssembliesListAndDirectories.Item1;
                        if (UnPackTestAssembliesListAndDirectories.Item2.Count > 0)
                        {
                            TestAssembliesDirectories = TestAssembliesDirectories.Concat(UnPackTestAssembliesListAndDirectories.Item2).ToList();
                        }
                    }
                }
                if (string.IsNullOrEmpty(TestAssembliesList))
                {
                    throw new Exception($"Cannot find any {ProjectSpec} project folders or assemblies at {TestRunner.TestsPath}.");
                }

                // Setup for screen recording
                var TestSettingsFile = ScreenRecordingTestSettingsFile(ThisJobName);

                string TestRunnerPath = TestRunner.WriteTestRunner(ThisJobName, ProjectSpec, TestCategories, TestAssembliesList, TestSettingsFile, TestRunner.TestsResultsPath, RecordScreen != null, JobSpecs);

                string TrxFile;
                if (string.IsNullOrEmpty(RetryFile))
                {
                    //Run Tests
                    TrxFile = RunTests(JobName, TestAssembliesList, TestAssembliesDirectories, TestSettingsFile, TestRunnerPath);
                }
                else
                {
                    TrxFile = RetryFile;
                }
                if (!string.IsNullOrEmpty(TrxFile))
                {
                    //Re-try Failures
                    for (var count = 0; count < RetryCount; count++)
                    {
                        RetryTestFailures(ThisJobName, TestAssembliesList, TestAssembliesDirectories, TestSettingsFile, TrxFile, count + 1);
                    }
                }
            }
            if (ApplyDotCover && JobName.Split(',').Count() > 1)
            {
                MergeDotCoverSnapshots();
            }
        }