Пример #1
0
        private bool RunTests(IEnumerable <string> sources)
        {
            // create/start test run
            if (EqtTrace.IsInfoEnabled)
            {
                EqtTrace.Info("RunTestsArgumentProcessor:Execute: Test run is starting.");
            }

            var runSettings = this.runSettingsManager.ActiveRunSettings.SettingsXml;

            if (EqtTrace.IsVerboseEnabled)
            {
                EqtTrace.Verbose("RunTestsArgumentProcessor:Execute: Queuing Test run.");
            }

            // for command line keep alive is always false.
            // for Windows Store apps it should be false, as Windows Store apps executor should terminate after finishing the test execution.
            var keepAlive = false;

            GenerateFakesUtilities.GenerateFakesSettings(this.commandLineOptions, this.commandLineOptions.Sources.ToList(), ref runSettings);

            var runRequestPayload = new TestRunRequestPayload()
            {
                Sources = this.commandLineOptions.Sources.ToList(), RunSettings = runSettings, KeepAlive = keepAlive, TestCaseFilter = this.commandLineOptions.TestCaseFilterValue
            };
            var result = this.testRequestManager.RunTests(runRequestPayload, null, this.testRunEventsRegistrar, Constants.DefaultProtocolConfig);

            if (EqtTrace.IsInfoEnabled)
            {
                EqtTrace.Info("RunTestsArgumentProcessor:Execute: Test run is completed.");
            }

            return(result);
        }
Пример #2
0
        public void FakesShouldNotBeGeneratedIfDisableAutoFakesSetToTrue()
        {
            CommandLineOptions.Instance.DisableAutoFakes = true;
            string runSettingsXml = @"<RunSettings><RunConfiguration><TargetFrameworkVersion>.netstandard,Version=5.0</TargetFrameworkVersion></RunConfiguration ></RunSettings>";

            GenerateFakesUtilities.GenerateFakesSettings(CommandLineOptions.Instance, new string[] { }, ref runSettingsXml);
            Assert.AreEqual(runSettingsXml, this.runSettings);
        }
        /// <summary>
        ///  Executes the selected tests
        /// </summary>
        private bool ExecuteSelectedTests()
        {
            bool result = true;

            if (this.selectedTestCases.Count > 0)
            {
                if (this.undiscoveredFilters.Count() != 0)
                {
                    string missingFilters = string.Join(", ", this.undiscoveredFilters);
                    string warningMessage = string.Format(CultureInfo.CurrentCulture, CommandLineResources.SomeTestsUnavailableAfterFiltering, this.discoveredTestCount, missingFilters);
                    this.output.Warning(warningMessage);
                }

                // for command line keep alive is always false.
                bool keepAlive = false;

                GenerateFakesUtilities.GenerateFakesSettings(this.commandLineOptions, this.commandLineOptions.Sources.ToList(), ref this.effectiveRunSettings);

                EqtTrace.Verbose("RunSpecificTestsArgumentProcessor:Execute: Test run is queued.");
                var runRequestPayload = new TestRunRequestPayload()
                {
                    TestCases = this.selectedTestCases.ToList(), RunSettings = this.effectiveRunSettings, KeepAlive = keepAlive
                };
                result &= this.testRequestManager.RunTests(runRequestPayload, null, null, Constants.DefaultProtocolConfig);
            }
            else
            {
                string warningMessage;
                if (this.discoveredTestCount > 0)
                {
                    // No tests that matched any of the given strings.
                    warningMessage = string.Format(CultureInfo.CurrentCulture, CommandLineResources.NoTestsAvailableAfterFiltering, this.discoveredTestCount, string.Join(", ", this.selectedTestNames));
                }
                else
                {
                    // No tests were discovered from the given sources.
                    warningMessage = string.Format(CultureInfo.CurrentUICulture, CommandLineResources.NoTestsAvailableInSources, string.Join(", ", this.commandLineOptions.Sources));

                    if (!this.commandLineOptions.UseVsixExtensions)
                    {
                        warningMessage = string.Format(CultureInfo.CurrentCulture, CommandLineResources.NoTestsFoundWarningMessageWithSuggestionToUseVsix, warningMessage, CommandLineResources.SuggestUseVsixExtensionsIfNoTestsIsFound);
                    }
                }

                this.output.Warning(warningMessage);
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Run Tests with given a set of test cases.
        /// </summary>
        /// <param name="testRunRequestPayload">TestRun request Payload</param>
        /// <param name="testHostLauncher">TestHost Launcher for the run</param>
        /// <param name="testRunEventsRegistrar">event registrar for run events</param>
        /// <param name="protocolConfig">Protocol related information</param>
        /// <returns>True, if successful</returns>
        public void RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLauncher testHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig)
        {
            EqtTrace.Info("TestRequestManager.RunTests: run tests started.");

            TestRunCriteria runCriteria = null;
            var             runsettings = testRunRequestPayload.RunSettings;

            if (testRunRequestPayload.TestPlatformOptions != null)
            {
                this.telemetryOptedIn = testRunRequestPayload.TestPlatformOptions.CollectMetrics;
            }

            var requestData = this.GetRequestData(protocolConfig);

            // Get sources to auto detect fx and arch for both run selected or run all scenario.
            var sources = GetSources(testRunRequestPayload);

            if (this.UpdateRunSettingsIfRequired(runsettings, sources, out string updatedRunsettings))
            {
                runsettings = updatedRunsettings;
            }

            if (InferRunSettingsHelper.AreRunSettingsCollectorsInCompatibleWithTestSettings(runsettings))
            {
                throw new SettingsException(string.Format(Resources.RunsettingsWithDCErrorMessage, runsettings));
            }

            var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettings);
            var batchSize        = runConfiguration.BatchSize;

            if (requestData.IsTelemetryOptedIn)
            {
                // Collect Metrics
                this.CollectMetrics(requestData, runConfiguration);

                // Collect Commands
                this.LogCommandsTelemetryPoints(requestData);

                // Collect data for Legacy Settings
                this.LogTelemetryForLegacySettings(requestData, runsettings);
            }

            if (!commandLineOptions.IsDesignMode)
            {
                // Generate fakes settings only for command line scenarios. In case of
                // Editors/IDEs, this responsibility is with the caller.
                GenerateFakesUtilities.GenerateFakesSettings(this.commandLineOptions, this.commandLineOptions.Sources.ToList(), ref runsettings);
            }

            if (testRunRequestPayload.Sources != null && testRunRequestPayload.Sources.Any())
            {
                runCriteria = new TestRunCriteria(
                    testRunRequestPayload.Sources,
                    batchSize,
                    testRunRequestPayload.KeepAlive,
                    runsettings,
                    this.commandLineOptions.TestStatsEventTimeout,
                    testHostLauncher,
                    testRunRequestPayload.TestPlatformOptions?.TestCaseFilter,
                    testRunRequestPayload.TestPlatformOptions?.FilterOptions);
            }
            else
            {
                runCriteria = new TestRunCriteria(
                    testRunRequestPayload.TestCases,
                    batchSize,
                    testRunRequestPayload.KeepAlive,
                    runsettings,
                    this.commandLineOptions.TestStatsEventTimeout,
                    testHostLauncher);
            }

            // Run tests
            try
            {
                this.RunTests(requestData, runCriteria, testRunEventsRegistrar, testRunRequestPayload.TestPlatformOptions);
                EqtTrace.Info("TestRequestManager.RunTests: run tests completed.");
            }
            finally
            {
                this.testPlatformEventSource.ExecutionRequestStop();

                // Post the run complete event
                this.metricsPublisher.Result.PublishMetrics(TelemetryDataConstants.TestExecutionCompleteEvent, requestData.MetricsCollection.Metrics);
            }
        }
Пример #5
0
        /// <inheritdoc />
        public void RunTests(
            TestRunRequestPayload testRunRequestPayload,
            ITestHostLauncher testHostLauncher,
            ITestRunEventsRegistrar testRunEventsRegistrar,
            ProtocolConfig protocolConfig)
        {
            EqtTrace.Info("TestRequestManager.RunTests: run tests started.");

            TestRunCriteria runCriteria = null;
            var             runsettings = testRunRequestPayload.RunSettings;

            if (testRunRequestPayload.TestPlatformOptions != null)
            {
                this.telemetryOptedIn = testRunRequestPayload.TestPlatformOptions.CollectMetrics;
            }

            var requestData = this.GetRequestData(protocolConfig);

            // Get sources to auto detect fx and arch for both run selected or run all scenario.
            var sources = GetSources(testRunRequestPayload);

            if (this.UpdateRunSettingsIfRequired(
                    runsettings,
                    sources,
                    testRunEventsRegistrar,
                    out string updatedRunsettings))
            {
                runsettings = updatedRunsettings;
            }

            if (InferRunSettingsHelper.AreRunSettingsCollectorsIncompatibleWithTestSettings(runsettings))
            {
                throw new SettingsException(
                          string.Format(
                              Resources.RunsettingsWithDCErrorMessage,
                              runsettings));
            }

            var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettings);
            var batchSize        = runConfiguration.BatchSize;

            if (requestData.IsTelemetryOptedIn)
            {
                // Collect metrics.
                this.CollectMetrics(requestData, runConfiguration);

                // Collect commands.
                this.LogCommandsTelemetryPoints(requestData);

                // Collect data for legacy settings.
                this.LogTelemetryForLegacySettings(requestData, runsettings);
            }

            // Get Fakes data collector settings.
            if (!string.Equals(Environment.GetEnvironmentVariable("VSTEST_SKIP_FAKES_CONFIGURATION"), "1"))
            {
                // The commandline options do not have sources in design time mode,
                // and so we fall back to using sources instead.
                if (this.commandLineOptions.Sources.Any())
                {
                    GenerateFakesUtilities.GenerateFakesSettings(
                        this.commandLineOptions,
                        this.commandLineOptions.Sources.ToList(),
                        ref runsettings);
                }
                else if (sources.Any())
                {
                    GenerateFakesUtilities.GenerateFakesSettings(
                        this.commandLineOptions,
                        sources,
                        ref runsettings);
                }
            }

            if (testRunRequestPayload.Sources != null && testRunRequestPayload.Sources.Any())
            {
                runCriteria = new TestRunCriteria(
                    testRunRequestPayload.Sources,
                    batchSize,
                    testRunRequestPayload.KeepAlive,
                    runsettings,
                    this.commandLineOptions.TestStatsEventTimeout,
                    testHostLauncher,
                    testRunRequestPayload.TestPlatformOptions?.TestCaseFilter,
                    testRunRequestPayload.TestPlatformOptions?.FilterOptions,
                    testRunRequestPayload.TestSessionInfo,
                    debugEnabledForTestSession: testRunRequestPayload.TestSessionInfo != null &&
                    testRunRequestPayload.DebuggingEnabled);
            }
            else
            {
                runCriteria = new TestRunCriteria(
                    testRunRequestPayload.TestCases,
                    batchSize,
                    testRunRequestPayload.KeepAlive,
                    runsettings,
                    this.commandLineOptions.TestStatsEventTimeout,
                    testHostLauncher,
                    testRunRequestPayload.TestSessionInfo,
                    debugEnabledForTestSession: testRunRequestPayload.TestSessionInfo != null &&
                    testRunRequestPayload.DebuggingEnabled);
            }

            // Run tests.
            try
            {
                this.RunTests(
                    requestData,
                    runCriteria,
                    testRunEventsRegistrar,
                    testRunRequestPayload.TestPlatformOptions);
                EqtTrace.Info("TestRequestManager.RunTests: run tests completed.");
            }
            finally
            {
                this.TestPlatformEventSourceInstance.ExecutionRequestStop();

                // Post the run complete event
                this.metricsPublisher.Result.PublishMetrics(
                    TelemetryDataConstants.TestExecutionCompleteEvent,
                    requestData.MetricsCollection.Metrics);
            }
        }