Exemple #1
0
        public void IsTestSettingsEnabledShouldReturnFalseIfRunsettingsDoesnotHaveTestSettings()
        {
            string runsettingsString = @"<RunSettings>
                                        <MSTest>
                                            <ForcedLegacyMode>true</ForcedLegacyMode>
                                        </MSTest>
                                    </RunSettings>";

            Assert.IsFalse(InferRunSettingsHelper.IsTestSettingsEnabled(runsettingsString));
        }
Exemple #2
0
        public void IsTestSettingsEnabledShouldReturnTrueIfRunsettingsHasTestSettings()
        {
            string runsettingsString = @"<RunSettings>
                                        <MSTest>
                                            <SettingsFile>C:\temp.testsettings</SettingsFile>
                                            <ForcedLegacyMode>true</ForcedLegacyMode>
                                        </MSTest>
                                    </RunSettings>";

            Assert.IsTrue(InferRunSettingsHelper.IsTestSettingsEnabled(runsettingsString));
        }
        private bool ShouldRunInNoIsolation(
            string runsettings,
            bool isParallelEnabled,
            bool isDataCollectorEnabled)
        {
            var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettings);

            if (runConfiguration.InIsolation)
            {
                if (EqtTrace.IsInfoEnabled)
                {
                    EqtTrace.Info("TestEngine.ShouldRunInNoIsolation: running test in isolation");
                }
                return(false);
            }

            // Run tests in isolation if run is authored using testsettings.
            if (InferRunSettingsHelper.IsTestSettingsEnabled(runsettings))
            {
                return(false);
            }

            var currentProcessPath = this.processHelper.GetCurrentProcessFileName();

            // If running with the dotnet executable, then don't run in in process.
            if (currentProcessPath.EndsWith("dotnet", StringComparison.OrdinalIgnoreCase) ||
                currentProcessPath.EndsWith("dotnet.exe", StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            // Return true if
            // 1) Not running in parallel;
            // 2) Data collector is not enabled;
            // 3) Target framework is x86 or anyCpu;
            // 4) DisableAppDomain is false;
            // 5) Not running in design mode;
            // 6) target framework is NETFramework (Desktop test);
            if (!isParallelEnabled &&
                !isDataCollectorEnabled &&
                (runConfiguration.TargetPlatform == Architecture.X86 || runConfiguration.TargetPlatform == Architecture.AnyCPU) &&
                !runConfiguration.DisableAppDomain &&
                !runConfiguration.DesignMode &&
                runConfiguration.TargetFramework.Name.IndexOf("netframework", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                if (EqtTrace.IsInfoEnabled)
                {
                    EqtTrace.Info("TestEngine.ShouldRunInNoIsolation: running test in process(inside vstest.console.exe process)");
                }
                return(true);
            }

            return(false);
        }
        /// <inheritdoc />
        public void Initialize(string argument)
        {
            // 1. Disable all other data collectors. Enable only those data collectors that are explicitly specified by user.
            // 2. Check if Code Coverage Data Collector is specified in runsettings, if not add it and also set enable to true.

            // if argument is null or doesn't contain any element, don't do anything.
            if (string.IsNullOrWhiteSpace(argument))
            {
                throw new CommandLineException(
                          string.Format(
                              CultureInfo.CurrentUICulture,
                              CommandLineResources.DataCollectorFriendlyNameInvalid,
                              argument));
            }

            if (InferRunSettingsHelper.IsTestSettingsEnabled(this.runSettingsManager.ActiveRunSettings.SettingsXml))
            {
                throw new SettingsException(string.Format(CommandLineResources.CollectWithTestSettingErrorMessage, argument));
            }
            AddDataCollectorToRunSettings(argument, this.runSettingsManager, this.fileHelper);
        }
Exemple #5
0
        private void LogTelemetryForLegacySettings(IRequestData requestData, string runsettings)
        {
            requestData.MetricsCollection.Add(
                TelemetryDataConstants.TestSettingsUsed,
                InferRunSettingsHelper.IsTestSettingsEnabled(runsettings));

            if (InferRunSettingsHelper.TryGetLegacySettingElements(
                    runsettings,
                    out Dictionary <string, string> legacySettingsTelemetry))
            {
                foreach (var ciData in legacySettingsTelemetry)
                {
                    // We are collecting telemetry for the legacy nodes and attributes used in the runsettings.
                    requestData.MetricsCollection.Add(
                        string.Format(
                            "{0}.{1}",
                            TelemetryDataConstants.LegacySettingPrefix,
                            ciData.Key),
                        ciData.Value);
                }
            }
        }
        /// <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 bool 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.IsTestSettingsEnabled(runsettings))
            {
                bool throwException = false;
                if (this.commandLineOptions.EnableCodeCoverage)
                {
                    var dataCollectorsFriendlyNames = XmlRunSettingsUtilities.GetDataCollectorsFriendlyName(runsettings);
                    if (dataCollectorsFriendlyNames.Count >= 2)
                    {
                        throwException = true;
                    }
                }
                else if (XmlRunSettingsUtilities.IsDataCollectionEnabled(runsettings))
                {
                    throwException = true;
                }

                if (throwException)
                {
                    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);
            }

            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);
                runCriteria.TestCaseFilter = testRunRequestPayload.TestPlatformOptions?.TestCaseFilter;
                runCriteria.FilterOptions  = testRunRequestPayload.TestPlatformOptions?.FilterOptions;
            }
            else
            {
                runCriteria = new TestRunCriteria(
                    testRunRequestPayload.TestCases,
                    batchSize,
                    testRunRequestPayload.KeepAlive,
                    runsettings,
                    this.commandLineOptions.TestStatsEventTimeout,
                    testHostLauncher);
            }

            var success = this.RunTests(requestData, runCriteria, testRunEventsRegistrar);

            EqtTrace.Info("TestRequestManager.RunTests: run tests completed, sucessful: {0}.", success);
            this.testPlatformEventSource.ExecutionRequestStop();

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

            return(success);
        }