Пример #1
0
        private static PerDocumentLocationXTestCases GetTestToDebug(string discoveredUnitTestsStore, string discoveredUnitDTestsStore)
        {
            var discoveredUnitTests  = PerDocumentLocationXTestCases.Deserialize(FilePath.NewFilePath(discoveredUnitTestsStore));
            var discoveredUnitDTests = PerDocumentLocationDTestCases.Deserialize(FilePath.NewFilePath(discoveredUnitDTestsStore));

            var dtc = discoveredUnitDTests.Values.First().First();
            var dl  = new DocumentLocation(dtc.CodeFilePath, dtc.LineNumber);

            var testToDebug = new PerDocumentLocationXTestCases();

            testToDebug.TryAdd(dl, discoveredUnitTests[dl]);

            return(testToDebug);
        }
Пример #2
0
        private static void DiscoverUnitTests(IEnumerable <IXTestDiscoverer> tds, string slnPath, string slnSnapPath, string discoveredUnitTestsStore, string discoveredUnitDTestsStore, string buildOutputRoot, DateTime timeFilter, string[] ignoredTests)
        {
            Logger.LogInfo("DiscoverUnitTests: starting discovering.");
            var testsPerAssembly  = new PerDocumentLocationXTestCases();
            var dtestsPerAssembly = new PerDocumentLocationDTestCases();

            FindAndExecuteForEachAssembly(
                buildOutputRoot,
                timeFilter,
                (string assemblyPath) =>
            {
                var disc = new XUnitTestDiscoverer();
                disc.TestDiscovered.AddHandler(
                    new FSharpHandler <XTestCase>(
                        (o, ea) =>
                {
                    if (ea.CodeFilePath != null)
                    {
                        var cfp         = PathBuilder.rebaseCodeFilePath(FilePath.NewFilePath(slnPath), FilePath.NewFilePath(slnSnapPath), FilePath.NewFilePath(ea.CodeFilePath));
                        ea.CodeFilePath = cfp.Item;
                    }
                    var dl = new DocumentLocation {
                        document = FilePath.NewFilePath(ea.CodeFilePath), line = DocumentCoordinate.NewDocumentCoordinate(ea.LineNumber)
                    };
                    var tests = testsPerAssembly.GetOrAdd(dl, _ => new ConcurrentBag <XTestCase>());
                    tests.Add(ea);
                    var dtests = dtestsPerAssembly.GetOrAdd(dl, _ => new ConcurrentBag <DTestCase>());
                    dtests.Add(FromXTestCase(ea));
                }));
                disc.DiscoverTests(tds, FilePath.NewFilePath(assemblyPath), ignoredTests);
            });

            testsPerAssembly.Serialize(FilePath.NewFilePath(discoveredUnitTestsStore));
            dtestsPerAssembly.Serialize(FilePath.NewFilePath(discoveredUnitDTestsStore));
            Logger.LogInfo("Written discovered unit tests to {0} & {1}.", discoveredUnitTestsStore, discoveredUnitDTestsStore);
        }
Пример #3
0
        private static int MainImpl(string[] args)
        {
            if (File.Exists(@"c:\debug.testhost.txt"))
            {
                while (true)
                {
                    System.Threading.Thread.Sleep(2000);
                }
            }

            LogInfo("TestHost: Entering Main.");
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomainUnhandledException);
            var command                   = args[0];
            var buildRoot                 = args[1];
            var codeCoverageStore         = args[2];
            var testResultsStore          = args[3];
            var discoveredUnitTestsStore  = args[4];
            var testFailureInfoStore      = args[5];
            var timeFilter                = args[6];
            var slnPath                   = args[7];
            var slnSnapPath               = args[8];
            var discoveredUnitDTestsStore = args[9];
            var ignoredTests              = (args[10] ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            var searchPath = FilePath.NewFilePath(Path.Combine(Path.GetDirectoryName(slnSnapPath), "packages"));

            if (command == "discover")
            {
                var tds = AdapterLoader.LoadDiscoverers(searchPath.Item);
                DiscoverUnitTests(tds, slnPath, slnSnapPath, discoveredUnitTestsStore, discoveredUnitDTestsStore, buildRoot, new DateTime(long.Parse(timeFilter)), ignoredTests);
                LogInfo("TestHost: Exiting Main.");
                return(0);
            }
            else
            {
                var tes            = AdapterLoader.LoadExecutors(searchPath.Item);
                var allTestsPassed = false;
                if (_debuggerAttached)
                {
                    allTestsPassed = RunTests(tes, slnPath, slnSnapPath, buildRoot, testResultsStore, testFailureInfoStore, GetTestToDebug(discoveredUnitTestsStore, discoveredUnitDTestsStore));
                }
                else
                {
                    allTestsPassed = ExecuteTestWithCoverageDataCollection(() => RunTests(tes, slnPath, slnSnapPath, buildRoot, testResultsStore, testFailureInfoStore, PerDocumentLocationXTestCases.Deserialize(FilePath.NewFilePath(discoveredUnitTestsStore))), codeCoverageStore);
                }

                LogInfo("TestHost: Exiting Main.");
                return(allTestsPassed ? 0 : 1);
            }
        }
Пример #4
0
        private static bool RunTests(IEnumerable <IXTestExecutor> tes, string slnPath, string slnSnapPath, string buildRoot, string testResultsStore, string testFailureInfoStore, PerDocumentLocationXTestCases discoveredUnitTests)
        {
            Stopwatch stopWatch = new Stopwatch();

            LogInfo("TestHost executing tests...");
            stopWatch.Start();
            var testResults     = new PerTestIdDResults();
            var testFailureInfo = new PerDocumentLocationTestFailureInfo();
            var tests           = from dc in discoveredUnitTests.Keys
                                  from t in discoveredUnitTests[dc]
                                  group t by t.Source;

            Parallel.ForEach(
                tests,
                new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            },
                test =>
            {
                LogInfo("Executing tests in {0}: Start.", test.Key);
                var exec = new XUnitTestExecutor();
                exec.TestExecuted.AddHandler(
                    new FSharpHandler <XTestResult>(
                        (o, ea) =>
                {
                    Func <string, string> rebaseCFP =
                        cfp =>
                    {
                        if (cfp == null)
                        {
                            return(null);
                        }

                        return(PathBuilder.rebaseCodeFilePath(FilePath.NewFilePath(slnPath), FilePath.NewFilePath(slnSnapPath), FilePath.NewFilePath(cfp)).ToString());
                    };

                    ea.TestCase.CodeFilePath = rebaseCFP(ea.TestCase.CodeFilePath);
                    RebaseCallStackDocumentReferences(rebaseCFP, ea);

                    NoteTestResults(testResults, ea, rebaseCFP);
                    NoteTestFailureInfo(testFailureInfo, ea);
                }));
                exec.ExecuteTests(tes, test);
                LogInfo("Executing tests in {0}: Done.", test.Key);
            });

            if (!_debuggerAttached)
            {
                testResults.Serialize(FilePath.NewFilePath(testResultsStore));
                testFailureInfo.Serialize(FilePath.NewFilePath(testFailureInfoStore));
            }

            stopWatch.Stop();
            var ts          = stopWatch.Elapsed;
            var elapsedTime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                            ts.Hours, ts.Minutes, ts.Seconds,
                                            ts.Milliseconds / 10);

            LogInfo("Done TestHost executing tests! [" + elapsedTime + "]");
            LogInfo("");

            var rrs =
                from tr in testResults
                from rr in tr.Value
                where rr.Outcome == DTestOutcome.TOFailed
                select rr;

            return(!rrs.Any());
        }