当前位置: 首页>>代码示例>>C#>>正文


C# IFrameworkHandle.SendMessage方法代码示例

本文整理汇总了C#中IFrameworkHandle.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# IFrameworkHandle.SendMessage方法的具体用法?C# IFrameworkHandle.SendMessage怎么用?C# IFrameworkHandle.SendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFrameworkHandle的用法示例。


在下文中一共展示了IFrameworkHandle.SendMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunTests

        public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            //Debugger.Launch();

            frameworkHandle.SendMessage(TestMessageLevel.Informational, Strings.EXECUTOR_STARTING);

            int executedSpecCount = 0;

            Settings settings = GetSettings(runContext);

            string currentAsssembly = string.Empty;
            try
            {

                foreach (IGrouping<string, TestCase> grouping in tests.GroupBy(x => x.Source)) {
                    currentAsssembly = grouping.Key;
                    frameworkHandle.SendMessage(TestMessageLevel.Informational, string.Format(Strings.EXECUTOR_EXECUTINGIN, currentAsssembly));

                    List<VisualStudioTestIdentifier> testsToRun = grouping.Select(test => test.ToVisualStudioTestIdentifier()).ToList();

                    this.executor.RunAssemblySpecifications(currentAsssembly, testsToRun, settings, uri, frameworkHandle);
                    executedSpecCount += grouping.Count();
                }

                frameworkHandle.SendMessage(TestMessageLevel.Informational, String.Format(Strings.EXECUTOR_COMPLETE, executedSpecCount, tests.GroupBy(x => x.Source).Count()));
            } catch (Exception ex)
            {
                frameworkHandle.SendMessage(TestMessageLevel.Error, string.Format(Strings.EXECUTOR_ERROR, currentAsssembly, ex.Message));
            }
            finally
            {
            }
        }
开发者ID:machine-visualstudio,项目名称:machine.vstestadapter,代码行数:33,代码来源:MspecTestAdapterExecutor.cs

示例2: RunTests

        /// <summary>
        /// Runs the tests.
        /// </summary>
        /// <param name="testBinaries">Where to look for tests to be run.</param>
        /// <param name="context">Context in which to run tests.</param>
        /// <param param name="framework">Where results should be stored.</param>
        public void RunTests(IEnumerable<string> testBinaries, IRunContext context, IFrameworkHandle framework)
        {
            _state = ExecutorState.Running;

            foreach (var testBinary in testBinaries)
            {
                if (_state == ExecutorState.Cancelling)
                {
                    _state = ExecutorState.Cancelled;
                    return;
                }

                var reportDocument = RunOrDebugCatchTest(testBinary, "*", context, framework);

                var tests = CatchTestDiscoverer.ListTestsInBinary(testBinary);
                foreach (var test in tests)
                {
                    try
                    {
                        var result = GetTestResultFromReport(test, reportDocument, framework);
                        framework.RecordResult(result);
                    }
                    catch (Exception ex)
                    {
                        // Log it and move on. It will show up to the user as a test that hasn't been run.
                        framework.SendMessage(TestMessageLevel.Error, "Exception occured when processing test source: " + test.FullyQualifiedName);
                        framework.SendMessage(TestMessageLevel.Informational, "Message: " + ex.Message + "\nStacktrace:" + ex.StackTrace);
                    }
                }
            }
        }
开发者ID:mrpi,项目名称:CatchVsTestAdapter,代码行数:37,代码来源:CatchTestExecutor.cs

示例3: RunTests

        public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            frameworkHandle.SendMessage(TestMessageLevel.Informational, Strings.EXECUTOR_STARTING);
            int executedSpecCount = 0;
            string currentAsssembly = string.Empty;
            try
            {
                ISpecificationExecutor specificationExecutor = this.adapterFactory.CreateExecutor();
                IEnumerable<IGrouping<string, TestCase>> groupBySource = tests.GroupBy(x => x.Source);
                foreach (IGrouping<string, TestCase> grouping in groupBySource)
                {
                    currentAsssembly = grouping.Key;
                    frameworkHandle.SendMessage(TestMessageLevel.Informational, string.Format(Strings.EXECUTOR_EXECUTINGIN, currentAsssembly));
                    specificationExecutor.RunAssemblySpecifications(currentAsssembly, MSpecTestAdapter.uri, runContext, frameworkHandle, grouping);
                    executedSpecCount += grouping.Count();
                }

                frameworkHandle.SendMessage(TestMessageLevel.Informational, String.Format(Strings.EXECUTOR_COMPLETE, executedSpecCount, groupBySource.Count()));
            }
            catch (Exception ex)
            {
                frameworkHandle.SendMessage(TestMessageLevel.Error, string.Format(Strings.EXECUTOR_ERROR, currentAsssembly, ex.Message));
            }
            finally
            {
            }
        }
开发者ID:ivanz,项目名称:machine.vstestadapter,代码行数:27,代码来源:MspecTestAdapterExecutor.cs

示例4: RunTests

        /// <summary>
        /// Runs the tests.
        /// </summary>
        /// <param name="tests">Tests to be run.</param>
        /// <param name="runContext">Context to use when executing the tests.</param>
        /// <param param name="frameworkHandle">Handle to the framework to record results and to do framework operations.</param>
        public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            m_cancelled = false;
            try
            {
                foreach (TestCase test in tests)
                {
                    if (m_cancelled)
                    {
                        break;
                    }
                    frameworkHandle.RecordStart(test);
                    frameworkHandle.SendMessage(TestMessageLevel.Informational, "Starting external test for " + test.DisplayName);
                    var testOutcome = RunExternalTest(test, runContext, frameworkHandle, test);
                    frameworkHandle.RecordResult(testOutcome);
                    frameworkHandle.SendMessage(TestMessageLevel.Informational, "Test result:" + testOutcome.Outcome.ToString());


                }
            }
            catch(Exception e)
            {
                frameworkHandle.SendMessage(TestMessageLevel.Error, "Exception during test execution: " +e.Message);
            }
}
开发者ID:XpiritBV,项目名称:ProtractorAdapter,代码行数:31,代码来源:ProtractorTestExecutor.cs

示例5: RunTests

        public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            _cancelled = false;

            foreach (string fileName in sources)
            {
                if (_cancelled)
                    break;

                try
                {
                    RunFileOrTest(frameworkHandle, runContext, fileName);

                    frameworkHandle.SendMessage(TestMessageLevel.Informational, "Process Done.");
                }
                catch (Exception ex)
                {
                    frameworkHandle.SendMessage(TestMessageLevel.Error, "Exception spawning nodeunit.cmd: " + ex.ToString());
                }
            }
        }
开发者ID:scrom,项目名称:NodeUnitTestAdapter,代码行数:21,代码来源:NodeUnitTestExecutor.cs

示例6: RunTests

        public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            this.frameworkHandle = frameworkHandle;

            foreach (var group in tests.GroupBy(t => t.Source))
            {
                frameworkHandle.SendMessage(TestMessageLevel.Informational, "Running selected: " + group.Key);

                using (var sandbox = new Sandbox<Executor>(group.Key))
                {
                    sandbox.Content.Execute(this, group.Select(t => t.FullyQualifiedName).ToArray());
                }
            }
        }
开发者ID:skoberlink,项目名称:NSpecTestAdapter,代码行数:14,代码来源:NSpecExecutor.cs

示例7: RunTests

        public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            var settingsProvider =
                runContext.RunSettings.GetSettings(VSTestSettings.SettingsName) as VSTestSettingsService;

            VSTestSettings settings;
            if (settingsProvider != null)
            {
                frameworkHandle.SendMessage(TestMessageLevel.Informational, "Found settings.");
                settings = settingsProvider.Settings;
            }
            else
            {
                frameworkHandle.SendMessage(TestMessageLevel.Informational, "No settings found. Using defaults.");
                settings = new VSTestSettings();
            }

            frameworkHandle.SendMessage(TestMessageLevel.Informational, settings.WorkingDirectory);

            _frameworkHandle = frameworkHandle;

            ITestLogger logger = new VSLogger(frameworkHandle);

            GTestConverter converter = new GTestConverter();
            IEnumerable<ITestSuite> suites = converter.ConvertToGTest(tests.ToArray(), logger);

            foreach (var suite in suites)
            {
                logger.Information(string.Format("Processing suite {0}...", suite.RunTarget));
                VSTracker tracker = new VSTracker(frameworkHandle, suite);
                GTestRunner runner = new GTestRunner(logger, false);

                runner.TestCompleted += tracker.TestCompleted;
                logger.Information(string.Format("Running suite {0}...", suite.RunTarget));
                runner.Run(suite);
            }
        }
开发者ID:etinquis,项目名称:gtest-gbar-1,代码行数:37,代码来源:GTestExecutor.cs

示例8: RunTestCase

        private void RunTestCase(
            IFrameworkHandle frameworkHandle,
            IRunContext runContext,
            TestCase test,
            Dictionary<string, PythonProjectSettings> sourceToSettings
        ) {
            var testResult = new TestResult(test);
            frameworkHandle.RecordStart(test);
            testResult.StartTime = DateTimeOffset.Now;

            PythonProjectSettings settings;
            if (!sourceToSettings.TryGetValue(test.Source, out settings)) {
                sourceToSettings[test.Source] = settings = LoadProjectSettings(test.Source, _interpreterService);
            }
            if (settings == null) {
                frameworkHandle.SendMessage(
                    TestMessageLevel.Error,
                    "Unable to determine interpreter to use for " + test.Source);
                RecordEnd(
                    frameworkHandle,
                    test,
                    testResult,
                    null,
                    "Unable to determine interpreter to use for " + test.Source,
                    TestOutcome.Failed);
                return;
            }

            var debugMode = PythonDebugMode.None;
            if (runContext.IsBeingDebugged && _app != null) {
                debugMode = settings.EnableNativeCodeDebugging ? PythonDebugMode.PythonAndNative : PythonDebugMode.PythonOnly;
            }

            var testCase = new PythonTestCase(settings, test, debugMode);

            var dte = _app != null ? _app.GetDTE() : null;
            if (dte != null && debugMode != PythonDebugMode.None) {
                dte.Debugger.DetachAll();
            }

            if (!File.Exists(settings.Factory.Configuration.InterpreterPath)) {
                frameworkHandle.SendMessage(TestMessageLevel.Error, "Interpreter path does not exist: " + settings.Factory.Configuration.InterpreterPath);
                return;
            }

            var env = new Dictionary<string, string>();
            var pythonPathVar = settings.Factory.Configuration.PathEnvironmentVariable;
            var pythonPath = testCase.SearchPaths;
            if (!string.IsNullOrWhiteSpace(pythonPathVar)) {
                if (_app != null) {
                    var settingsManager = SettingsManagerCreator.GetSettingsManager(dte);
                    if (settingsManager != null) {
                        var store = settingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings);
                        if (store != null && store.CollectionExists(@"PythonTools\Options\General")) {
                            var settingStr = store.GetString(@"PythonTools\Options\General", "ClearGlobalPythonPath", "True");
                            bool settingBool;
                            if (bool.TryParse(settingStr, out settingBool) && !settingBool) {
                                pythonPath += ";" + Environment.GetEnvironmentVariable(pythonPathVar);
                            }
                        }
                    }
                }
                env[pythonPathVar] = pythonPath;
            }

            foreach (var envVar in testCase.Environment) {
                env[envVar.Key] = envVar.Value;
            }

            using (var proc = ProcessOutput.Run(
                !settings.IsWindowsApplication ? 
                    settings.Factory.Configuration.InterpreterPath :
                    settings.Factory.Configuration.WindowsInterpreterPath,
                testCase.Arguments,
                testCase.WorkingDirectory,
                env,
                false,
                null
            )) {
                bool killed = false;

#if DEBUG
                frameworkHandle.SendMessage(TestMessageLevel.Informational, "cd " + testCase.WorkingDirectory);
                frameworkHandle.SendMessage(TestMessageLevel.Informational, "set " + (pythonPathVar ?? "") + "=" + (pythonPath ?? ""));
                frameworkHandle.SendMessage(TestMessageLevel.Informational, proc.Arguments);
#endif

                proc.Wait(TimeSpan.FromMilliseconds(500));
                if (debugMode != PythonDebugMode.None) {
                    if (proc.ExitCode.HasValue) {
                        // Process has already exited
                        frameworkHandle.SendMessage(TestMessageLevel.Error, "Failed to attach debugger because the process has already exited.");
                        if (proc.StandardErrorLines.Any()) {
                            frameworkHandle.SendMessage(TestMessageLevel.Error, "Standard error from Python:");
                            foreach (var line in proc.StandardErrorLines) {
                                frameworkHandle.SendMessage(TestMessageLevel.Error, line);
                            }
                        }
                    }

//.........这里部分代码省略.........
开发者ID:omnimark,项目名称:PTVS,代码行数:101,代码来源:TestExecutor.cs

示例9: RunTestCases

        private void RunTestCases(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle) {
            // May be null, but this is handled by RunTestCase if it matters.
            // No VS instance just means no debugging, but everything else is
            // okay.
            using (var app = VisualStudioApp.FromEnvironmentVariable(NodejsConstants.NodeToolsProcessIdEnvironmentVariable)) {
                // .njsproj file path -> project settings
                var sourceToSettings = new Dictionary<string, NodejsProjectSettings>();

                foreach (var test in tests) {
                    if (_cancelRequested.WaitOne(0)) {
                        break;
                    }

                    try {
                        RunTestCase(app, frameworkHandle, runContext, test, sourceToSettings);
                    } catch (Exception ex) {
                        frameworkHandle.SendMessage(TestMessageLevel.Error, ex.ToString());
                    }
                }
            }
        }
开发者ID:mauricionr,项目名称:nodejstools,代码行数:21,代码来源:TestExecutor.cs

示例10: RunTestCase

        private void RunTestCase(VisualStudioApp app, IFrameworkHandle frameworkHandle, IRunContext runContext, TestCase test, Dictionary<string, NodejsProjectSettings> sourceToSettings) {
            var testResult = new TestResult(test);
            frameworkHandle.RecordStart(test);
            testResult.StartTime = DateTimeOffset.Now;
            NodejsProjectSettings settings;
            if (!sourceToSettings.TryGetValue(test.Source, out settings)) {
                sourceToSettings[test.Source] = settings = LoadProjectSettings(test.Source);
            }
            if (settings == null) {
                frameworkHandle.SendMessage(
                    TestMessageLevel.Error,
                    "Unable to determine interpreter to use for " + test.Source);
                RecordEnd(
                    frameworkHandle,
                    test,
                    testResult,
                    null,
                    "Unable to determine interpreter to use for " + test.Source,
                    TestOutcome.Failed);
                return;
            }

            NodejsTestInfo testInfo = new NodejsTestInfo(test.FullyQualifiedName);
            List<string> args = new List<string>();
            int port = 0;
            if (runContext.IsBeingDebugged && app != null) {
                app.GetDTE().Debugger.DetachAll();
                args.AddRange(GetDebugArgs(settings, out port));
            }

            var workingDir = Path.GetDirectoryName(CommonUtils.GetAbsoluteFilePath(settings.WorkingDir, testInfo.ModulePath));
            args.AddRange(GetInterpreterArgs(test, workingDir, settings.ProjectRootDir));

            //Debug.Fail("attach debugger");
            if (!File.Exists(settings.NodeExePath)) {
                frameworkHandle.SendMessage(TestMessageLevel.Error, "Interpreter path does not exist: " + settings.NodeExePath);
                return;
            }
            lock (_syncObject) {
                _nodeProcess = ProcessOutput.Run(
                                        settings.NodeExePath,
                                        args,
                                        workingDir,
                                        null,
                                        false,
                                        null,
                                        false);

#if DEBUG
                frameworkHandle.SendMessage(TestMessageLevel.Informational, "cd " + workingDir);
                frameworkHandle.SendMessage(TestMessageLevel.Informational, _nodeProcess.Arguments);
#endif

                _nodeProcess.Wait(TimeSpan.FromMilliseconds(500));
                if (runContext.IsBeingDebugged && app != null) {
                    try {
                        //the '#ping=0' is a special flag to tell VS node debugger not to connect to the port,
                        //because a connection carries the consequence of setting off --debug-brk, and breakpoints will be missed.
                        string qualifierUri = string.Format("tcp://localhost:{0}#ping=0", port);
                        while (!app.AttachToProcess(_nodeProcess, NodejsRemoteDebugPortSupplierUnsecuredId, qualifierUri)) {
                            if (_nodeProcess.Wait(TimeSpan.FromMilliseconds(500))) {
                                break;
                            }
                        }
#if DEBUG
                    } catch (COMException ex) {
                        frameworkHandle.SendMessage(TestMessageLevel.Error, "Error occurred connecting to debuggee.");
                        frameworkHandle.SendMessage(TestMessageLevel.Error, ex.ToString());
                        KillNodeProcess();
                    }
#else
                    } catch (COMException) {
                        frameworkHandle.SendMessage(TestMessageLevel.Error, "Error occurred connecting to debuggee.");
                        KillNodeProcess();
                    }
#endif
                }
            }
开发者ID:mauricionr,项目名称:nodejstools,代码行数:78,代码来源:TestExecutor.cs

示例11: RunTests

 public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
 {
     foreach(var item in sources)
         frameworkHandle.SendMessage(TestMessageLevel.Informational, $"{item}");
 }
开发者ID:drunkcod,项目名称:Cone,代码行数:5,代码来源:ConeTestExecutor.cs

示例12: RunFileOrTest

        private static void RunFileOrTest(IFrameworkHandle frameworkHandle, IRunContext runContext, string fileName, string testName = null)
        {
            frameworkHandle.SendMessage(TestMessageLevel.Informational, "runContext.SolutionDirectory: " + runContext.SolutionDirectory);
            frameworkHandle.SendMessage(TestMessageLevel.Informational, "runContext.TestRunDirectory: " + runContext.TestRunDirectory);
            frameworkHandle.SendMessage(TestMessageLevel.Informational, "source: " + fileName);

            string nodeFullPath = NodeJsHelper.LocateNodeJs();

            Process proc = new Process();

            proc.StartInfo.FileName = nodeFullPath;
            proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(fileName);
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.RedirectStandardInput = true;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError = true;
            proc.StartInfo.CreateNoWindow = true;

            proc.OutputDataReceived += (sender, args) =>
            {
                var data = args.Data;

                if (!string.IsNullOrEmpty(data))
                {
                    frameworkHandle.SendMessage(TestMessageLevel.Informational, "> " + data);

                    if (data.Contains("Error: Cannot find module 'nodeunit'"))
                    {
                        if (!string.IsNullOrEmpty(testName))
                        {
                            GenericFailTest(frameworkHandle, fileName, testName, data);
                        }
                    }
                    else
                    {
                        try
                        {
                            var result = JsonConvert.DeserializeObject<NodeUnitTestResult>(data);

                            if (result != null && !string.IsNullOrEmpty(result.TestName))
                            {
                                var testCase = new TestCase(result.TestName, NodeUnitTestExecutor.ExecutorUri, fileName) { DisplayName = result.TestName };
                                var testResult = new TestResult(testCase) { DisplayName = result.TestName };
                                testResult.Duration = TimeSpan.FromSeconds(Math.Max(.001, result.Duration));
                                testResult.Outcome = result.Passed ? TestOutcome.Passed : TestOutcome.Failed;

                                if (result.Assertions.Length > 0)
                                {
                                    var first = result.Assertions.First();
                                    testResult.ErrorStackTrace = FormatStackTrace(first.Stack);
                                    testResult.ErrorMessage = first.Message;
                                }

                                frameworkHandle.SendMessage(TestMessageLevel.Informational, "Recording Result for " + testCase.DisplayName + " (" + testResult.Outcome.ToString() + ")");
                                frameworkHandle.RecordResult(testResult);
                            }
                        }
                        catch (Newtonsoft.Json.JsonException)
                        {
                            //frameworkHandle.SendMessage(TestMessageLevel.Informational, data);
                        }
                    }
                }
            };

            proc.ErrorDataReceived += (sender, args) =>
            {
                if (!string.IsNullOrEmpty(args.Data))
                {
                    frameworkHandle.SendMessage(TestMessageLevel.Warning, "^ " + args.Data);

                    if (args.Data.Contains("Error: Cannot find module 'nodeunit'"))
                    {
                        if (!string.IsNullOrEmpty(testName))
                        {
                            GenericFailTest(frameworkHandle, fileName, testName, args.Data);
                        }
                    }
                }
            };

            frameworkHandle.SendMessage(TestMessageLevel.Informational, "Process FileName: " + proc.StartInfo.FileName);
            frameworkHandle.SendMessage(TestMessageLevel.Informational, "Process Arguments: " + proc.StartInfo.Arguments);
            frameworkHandle.SendMessage(TestMessageLevel.Informational, "Process WorkingDirectory: " + proc.StartInfo.WorkingDirectory);

            proc.Start();
            proc.BeginOutputReadLine();
            proc.BeginErrorReadLine();

            proc.StandardInput.Write(Resources.RunTests);

            string testFile = Path.GetFileName(fileName).Replace("\\", "\\\\");
            string jsCommand = "runTests(\"" + testFile + "\"";
            if (!string.IsNullOrEmpty(testName))
                jsCommand += ", \"" + testName + "\"";
            jsCommand += ");";
            frameworkHandle.SendMessage(TestMessageLevel.Informational, "Process Emitting Command: " + jsCommand);
            proc.StandardInput.Write(jsCommand);
            proc.StandardInput.Close();

//.........这里部分代码省略.........
开发者ID:scrom,项目名称:NodeUnitTestAdapter,代码行数:101,代码来源:NodeUnitTestExecutor.cs

示例13: RunProtractor

        private string RunProtractor(TestCase test, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            var resultFile = Path.GetFileNameWithoutExtension(test.Source);
            resultFile += ".result.json";
            
            resultFile = Path.Combine(Path.GetTempPath(), resultFile);
            frameworkHandle.SendMessage(TestMessageLevel.Informational, "result file: " + resultFile);
           
            ProcessStartInfo info = new ProcessStartInfo()
            {
                Arguments = string.Format("--resultJsonOutputFile \"{0}\" --specs \"{1}\" --framework jasmine", resultFile, test.Source),
                FileName = "protractor.cmd"
            };

            frameworkHandle.SendMessage(TestMessageLevel.Informational, "starting protractor with arguments:" + info.Arguments);


            Process p = new Process();
            p.StartInfo = info;
            p.Start();
            p.WaitForExit();
            frameworkHandle.SendMessage(TestMessageLevel.Informational, "Protractor run done exit code:"+ p.ExitCode.ToString());

            return resultFile;
        }
开发者ID:XpiritBV,项目名称:ProtractorAdapter,代码行数:25,代码来源:ProtractorTestExecutor.cs

示例14: RunTestCases

        private void RunTestCases(
            IEnumerable<TestCase> tests,
            IRunContext runContext,
            IFrameworkHandle frameworkHandle
        ) {
            // .pyproj file path -> project settings
            var sourceToSettings = new Dictionary<string, PythonProjectSettings>();

            foreach (var test in tests) {
                if (_cancelRequested.WaitOne(0)) {
                    break;
                }

                try {
                    RunTestCase(frameworkHandle, runContext, test, sourceToSettings);
                } catch (Exception ex) {
                    frameworkHandle.SendMessage(TestMessageLevel.Error, ex.ToString());
                }
            }
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:20,代码来源:TestExecutor.cs

示例15: RunTests

        public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            foreach (var test in tests)
            {
                if (this.canceled)
                {
                    return;
                }

                var result = new TestResult(test);

                var target = System.IO.Path.ChangeExtension(test.Source, ".feature");

                try
                {
                    System.IO.File.Copy(test.Source, target);

                    var appDataPath = Environment.GetEnvironmentVariable("APPDATA");
                    var nodePath = System.IO.Path.Combine(appDataPath, "npm");
                    var cucumberPath = System.IO.Path.Combine(nodePath, "node_modules\\cucumber\\bin\\cucumber.js");
                    System.Diagnostics.ProcessStartInfo procStartInfo = runContext.IsBeingDebugged ?
                        new System.Diagnostics.ProcessStartInfo("node", $"--debug=5858 \"{cucumberPath}\" \"{target}:{test.LineNumber}\" -f json") :
                        new System.Diagnostics.ProcessStartInfo("node", $"\"{cucumberPath}\" \"{target}:{test.LineNumber}\" -f json");

                    // The following commands are needed to redirect the standard output.
                    // This means that it will be redirected to the Process.StandardOutput StreamReader.
                    procStartInfo.RedirectStandardOutput = true;
                    procStartInfo.RedirectStandardError = true;
                    procStartInfo.UseShellExecute = false;
                    procStartInfo.CreateNoWindow = true;
                    System.Diagnostics.Process proc = new System.Diagnostics.Process();
                    proc.StartInfo = procStartInfo;
                    proc.Start();

                    if (runContext.IsBeingDebugged)
                    {
                        DteHelpers.DebugAttachToNode(proc.Id, 5678);
                    }

                    proc.WaitForExit();
                    var error = proc.StandardError.ReadToEnd();
                    var output = proc.StandardOutput.ReadToEnd();

                    var features = JArray.Parse(output);

                    // frameworkHandle.SendMessage(Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Informational, output);
                    foreach (var feature in features)
                    {
                        frameworkHandle.SendMessage(Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Informational, $"{feature["keyword"]}: {feature["name"]}");

                        foreach (var element in feature["elements"])
                        {
                            frameworkHandle.SendMessage(Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Informational, $"{element["keyword"]}: {element["name"]}");
                            frameworkHandle.SendMessage(Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Informational, $"{element["description"]}");

                            bool passed = true;
                            var duration = 0L;
                            foreach (var step in element["steps"])
                            {
                                var message = $"{step["keyword"]}{step["name"]}";
                                duration = duration + (long)step["result"]["duration"];
                                frameworkHandle.SendMessage(Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Informational, message);
                                if ((string)step["result"]["status"] == "failed")
                                {
                                    result.ErrorMessage = (string)step["result"]["error_message"];
                                    frameworkHandle.SendMessage(Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Informational, $"{result.ErrorMessage}");
                                    passed = false;
                                }
                            }

                            result.Duration = TimeSpan.FromTicks(duration);

                            if (passed)
                            {
                                result.Outcome = TestOutcome.Passed;
                            }
                            else
                            {
                                result.Outcome = TestOutcome.Failed;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    result.Outcome = TestOutcome.Failed;
                    result.ErrorMessage = ex.Message + ex.StackTrace;
                }
                finally
                {
                    System.IO.File.Delete(target);
                }

                frameworkHandle.RecordResult(result);
            }
        }
开发者ID:endjin,项目名称:CucumberJS.TestAdapter,代码行数:96,代码来源:CucumberJsTestExecutor.cs


注:本文中的IFrameworkHandle.SendMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。