Esempio n. 1
0
        private void RunTests(IEnumerable <string> filePaths, bool openInBrowser = false, bool withCodeCoverage = false, bool withDebugger = false)
        {
            if (!testingInProgress)
            {
                lock (syncLock)
                {
                    if (!testingInProgress)
                    {
                        dte.Documents.SaveAll();
                        var solutionDir = Path.GetDirectoryName(dte.Solution.FullName);
                        testingInProgress = true;

                        Task.Factory.StartNew(
                            () =>
                        {
                            try
                            {
                                // If settings file environments have not yet been initialized, do so here.
                                if (settingsEnvironments == null || settingsEnvironments.Count == 0)
                                {
                                    InitializeSettingsFileEnvironments();
                                }

                                var options = new TestOptions
                                {
                                    MaxDegreeOfParallelism = Settings.MaxDegreeOfParallelism,
                                    CoverageOptions        = new CoverageOptions
                                    {
                                        Enabled = withCodeCoverage
                                    },

                                    CustomTestLauncher = withDebugger ? ChutzpahContainer.Get <VsDebuggerTestLauncher>() : null,
                                    TestLaunchMode     = GetTestLaunchMode(openInBrowser, withDebugger),
                                    ChutzpahSettingsFileEnvironments = settingsEnvironments
                                };
                                var result = testRunner.RunTests(filePaths, options, runnerCallback);

                                if (result.CoverageObject != null)
                                {
                                    var path = CoverageOutputGenerator.WriteHtmlFile(Path.Combine(solutionDir, Constants.CoverageHtmlFileName), result.CoverageObject);
                                    processHelper.LaunchLocalFileInBrowser(path);
                                }
                            }
                            catch (Exception e)
                            {
                                Logger.Log("Error while running tests", "ChutzpahPackage", e);
                            }
                            finally
                            {
                                testingInProgress = false;
                            }
                        });
                    }
                }
            }
        }