public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            if (Environment.GetEnvironmentVariable("ATTACH_DEBUGGER_CHUTZPAH") != null)
            {
                Debugger.Launch();
            }

            ChutzpahTracer.TraceInformation("Begin Test Adapter Run Tests");

            var settingsProvider = runContext.RunSettings.GetSettings(AdapterConstants.SettingsName) as ChutzpahAdapterSettingsProvider;
            var settings         = settingsProvider != null ? settingsProvider.Settings : new ChutzpahAdapterSettings();

            ChutzpahTracingHelper.Toggle(settings.EnabledTracing);

            var testOptions = new TestOptions
            {
                TestLaunchMode =
                    runContext.IsBeingDebugged ? TestLaunchMode.Custom:
                    settings.OpenInBrowser ? TestLaunchMode.FullBrowser:
                    TestLaunchMode.HeadlessBrowser,
                CustomTestLauncher               = runContext.IsBeingDebugged ? ChutzpahContainer.Get <VsDebuggerTestLauncher>() : null,
                MaxDegreeOfParallelism           = runContext.IsBeingDebugged ? 1 : settings.MaxDegreeOfParallelism,
                ChutzpahSettingsFileEnvironments = new ChutzpahSettingsFileEnvironments(settings.ChutzpahSettingsFileEnvironments)
            };

            testOptions.CoverageOptions.Enabled = runContext.IsDataCollectionEnabled;

            var callback = new ParallelRunnerCallbackAdapter(new ExecutionCallback(frameworkHandle, runContext));

            testRunner.RunTests(sources, testOptions, callback);

            ChutzpahTracer.TraceInformation("End Test Adapter Run Tests");
        }
Пример #2
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by Visual Studio.
        /// </summary>
        protected override void Initialize()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", ToString()));
            base.Initialize();

            dte = (DTE2)GetService(typeof(DTE));
            if (dte == null)
            {
                //if dte is null then we throw a exception
                //this is a fatal error
                throw new ArgumentNullException("dte");
            }

            testRunner = TestRunner.Create();

            processHelper = ChutzpahContainer.Get <IProcessHelper>();
            Logger        = new Logger(this);
            Settings      = GetDialogPage(typeof(ChutzpahSettings)) as ChutzpahSettings;

            statusBar      = GetService(typeof(SVsStatusbar)) as IVsStatusbar;
            runnerCallback = new ParallelRunnerCallbackAdapter(new VisualStudioRunnerCallback(dte, statusBar));


            // Add our command handlers for menu (commands must exist in the .vsct file)
            var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Command - Run JS Tests
                var runJsTestsCmd    = new CommandID(GuidList.guidChutzpahCmdSet, (int)PkgCmdIDList.cmdidRunJSTests);
                var runJsTestMenuCmd = new OleMenuCommand(RunJSTestCmdCallback, runJsTestsCmd);
                runJsTestMenuCmd.BeforeQueryStatus += RunJSTestsCmdQueryStatus;
                mcs.AddCommand(runJsTestMenuCmd);

                // Command - Run JS tests in browser
                var runJsTestsInBrowserCmd    = new CommandID(GuidList.guidChutzpahCmdSet, (int)PkgCmdIDList.cmdidRunInBrowser);
                var runJsTestInBrowserMenuCmd = new OleMenuCommand(RunJSTestInBrowserCmdCallback, runJsTestsInBrowserCmd);
                runJsTestInBrowserMenuCmd.BeforeQueryStatus += RunJSTestsInBrowserCmdQueryStatus;
                mcs.AddCommand(runJsTestInBrowserMenuCmd);

                // Command - Run Code Coverage
                var runJsTestCodeCoverageCmd     = new CommandID(GuidList.guidChutzpahCmdSet, (int)PkgCmdIDList.cmdidRunCodeCoverage);
                var runJsTestCodeCoverageMenuCmd = new OleMenuCommand(RunCodeCoverageCmdCallback, runJsTestCodeCoverageCmd);
                runJsTestCodeCoverageMenuCmd.BeforeQueryStatus += RunCodeCoverageCmdQueryStatus;
                mcs.AddCommand(runJsTestCodeCoverageMenuCmd);


                var runJsTestDebuggerCmd     = new CommandID(GuidList.guidChutzpahCmdSet, (int)PkgCmdIDList.cmdidDebugTests);
                var runJsTestDebuggerMenuCmd = new OleMenuCommand(RunDebuggerCmdCallback, runJsTestDebuggerCmd);
                runJsTestDebuggerMenuCmd.BeforeQueryStatus += RunDebuggerCmdQueryStatus;
                mcs.AddCommand(runJsTestDebuggerMenuCmd);
            }


            this.solutionListener = new SolutionEventsListener(this);
            this.solutionListener.SolutionUnloaded       += OnSolutionUnloaded;
            this.solutionListener.SolutionProjectChanged += OnSolutionProjectChanged;
            this.solutionListener.StartListeningForChanges();
        }
Пример #3
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;
                            }
                        });
                    }
                }
            }
        }
Пример #4
0
 public ChutzpahTestContainerDiscoverer(
     [Import(typeof(IServiceProvider))] IServiceProvider serviceProvider,
     IChutzpahSettingsMapper settingsMapper,
     ISolutionEventsListener solutionListener,
     ITestFilesUpdateWatcher testFilesUpdateWatcher,
     ITestFileAddRemoveListener testFilesAddRemoveListener)
     : this(
         serviceProvider,
         settingsMapper,
         new Logger(serviceProvider),
         solutionListener,
         testFilesUpdateWatcher,
         testFilesAddRemoveListener,
         TestRunner.Create(),
         ChutzpahContainer.Get <IFileProbe>(),
         ChutzpahContainer.Get <IChutzpahTestSettingsService>())
 {
 }
Пример #5
0
        public override void TestSuiteFinished(TestContext context, TestCaseSummary testResultsSummary)
        {
            base.TestSuiteFinished(context, testResultsSummary);

            if (!runContext.IsDataCollectionEnabled || testResultsSummary.CoverageObject == null)
            {
                return;
            }

            try
            {
                // If we do not have a solutiondirectory, we assume that we are running in tfs build
                // In that case we only write to the testrundirectory and do not open a browser
                if (string.IsNullOrEmpty(runContext.SolutionDirectory))
                {
                    ChutzpahTracer.TraceInformation("Chutzpah runs in TFSBuild, writing coverage file to {0}", runContext.TestRunDirectory);

                    var directory = runContext.TestRunDirectory;
                    CoverageOutputGenerator.WriteHtmlFile(Path.Combine(directory, Constants.CoverageHtmlFileName), testResultsSummary.CoverageObject);
                }
                else
                {
                    ChutzpahTracer.TraceInformation("Chutzpah runs not in TFSBuild opening coverage file in browser");

                    var directory        = runContext.SolutionDirectory;
                    var coverageHtmlFile = CoverageOutputGenerator.WriteHtmlFile(Path.Combine(directory, Constants.CoverageHtmlFileName), testResultsSummary.CoverageObject);
                    var processHelper    = ChutzpahContainer.Get <IProcessHelper>();

                    processHelper.LaunchLocalFileInBrowser(coverageHtmlFile);
                }
            }
            catch (Exception e)
            {
                frameworkHandle.SendMessage(TestMessageLevel.Error, string.Format("Error while writing coverage output: {0}", e));
            }
        }