Exemplo n.º 1
0
        /// <summary>
        /// Creates an automation provider test run entity. Use this method to implement the automation
        /// provider test run creation and to modify the loaded Rhino.Api.Contracts.AutomationProvider.RhinoTestRun.
        /// </summary>
        /// <param name="testRun">Rhino.Api.Contracts.AutomationProvider.RhinoTestRun object to modify before creating.</param>
        /// <returns>Rhino.Api.Contracts.AutomationProvider.RhinoTestRun based on provided test cases.</returns>
        public override RhinoTestRun OnCreateTestRun(RhinoTestRun testRun)
        {
            // setup: request body
            var customField = jiraClient.GetCustomField(TestExecutionSchema);
            var testCases   = JsonConvert.SerializeObject(testRun.TestCases.Select(i => i.Key));

            // load JSON body
            var comment     = Utilities.GetActionSignature("created");
            var requestBody = Assembly.GetExecutingAssembly().ReadEmbeddedResource("create_test_execution_xray.txt")
                              .Replace("[project-key]", Configuration.ConnectorConfiguration.Project)
                              .Replace("[run-title]", TestRun.Title)
                              .Replace("[custom-1]", customField)
                              .Replace("[tests-repository]", testCases)
                              .Replace("[type-name]", $"{capabilities[AtlassianCapabilities.ExecutionType]}")
                              .Replace("[assignee]", Configuration.ConnectorConfiguration.UserName);
            var responseBody = jiraClient.Create(requestBody, comment);

            // setup
            testRun.Key  = $"{responseBody["key"]}";
            testRun.Link = $"{responseBody["self"]}";
            testRun.Context["runtimeid"] = $"{responseBody["id"]}";
            testRun.Context[ContextEntry.Configuration] = Configuration;

            // test steps handler
            foreach (var testCase in TestRun.TestCases)
            {
                testCase.SetRuntimeKeys(testRun.Key);
            }
            return(testRun);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets all tests under this RhinoTestRun execution.
        /// </summary>
        /// <param name="testRun">RhinoTestRun by which to get tests.</param>
        public static JToken GetTests(this RhinoTestRun testRun)
        {
            // setup
            var executor = new JiraCommandsExecutor(testRun.GetAuthentication());

            // get results
            var response = RavenCommandsRepository.GetTestsByExecution(testRun.Key).Send(executor).AsJToken();

            // return all tests
            return(response is JArray ? response : JToken.Parse("[]"));
        }
        /// <summary>
        /// Completes automation provider test run results, if any were missed or bypassed.
        /// </summary>
        /// <param name="testRun">Rhino.Api.Contracts.AutomationProvider.RhinoTestRun results object to complete by.</param>
        public override void CompleteTestRun(RhinoTestRun testRun)
        {
            // exit conditions
            if (Configuration.IsDryRun())
            {
                return;
            }

            // setup: failed to update
            var inStatus = new[] { "TODO", "EXECUTING" };

            // get all test keys to re-assign outcome
            var testResults = testRun
                              .GetTests()
                              .Where(i => inStatus.Contains($"{i["status"]}"))
                              .Select(i => $"{i["key"]}");

            // iterate: pass/fail
            foreach (var testCase in testRun.TestCases.Where(i => testResults.Contains(i.Key) && !i.Inconclusive))
            {
                DoUpdateTestResult(testCase, inline: false);
            }
            // iterate: align all runs
            var dataTests = testRun.TestCases.Where(i => i.Iteration > 0).Select(i => i.Key).Distinct();
            var options   = new ParallelOptions {
                MaxDegreeOfParallelism = 1
            };

            Parallel.ForEach(dataTests, options, testCase =>
            {
                var outcome = testRun.TestCases.Any(i => i.Key.Equals(testCase) && !i.Actual) ? "FAIL" : "PASS";
                if (outcome == "FAIL")
                {
                    testRun.TestCases.FirstOrDefault(i => !i.Actual && i.Key.Equals(testCase))?.SetOutcomeByRun(outcome);
                    return;
                }
                testRun.TestCases.FirstOrDefault(i => i.Actual && i.Key.Equals(testCase))?.SetOutcomeByRun(outcome);
            });
            // iterate: inconclusive
            foreach (var testCase in testRun.TestCases.Where(i => i.Inconclusive))
            {
                DoUpdateTestResult(testCase, inline: true);
            }

            // test plan
            AttachToTestPlan(testRun);

            // close
            var comment = Utilities.GetActionSignature("closed");

            jiraClient.CreateTransition(idOrKey: testRun.Key, transition: "Closed", resolution: "Done", comment);
        }
Exemplo n.º 4
0
        private static void ProcessOutcome(RhinoTestRun outcome)
        {
            // constants: logging
            const string M =
                "Total of [{0}] tests failed and stopped the process. Please review your tests results report.";

            // exit conditions
            if (outcome.TotalFail == 0)
            {
                Environment.Exit(0);
            }

            // exit with failure code
            Console.Error.WriteLine(string.Format(M, outcome.TotalFail));
            Environment.Exit(errorCode);
        }
        /// <summary>
        /// Creates an automation provider test run entity. Use this method to implement the automation
        /// provider test run creation and to modify the loaded Rhino.Api.Contracts.AutomationProvider.RhinoTestRun.
        /// </summary>
        /// <param name="testRun">Rhino.Api.Contracts.AutomationProvider.RhinoTestRun object to modify before creating.</param>
        /// <returns>Rhino.Api.Contracts.AutomationProvider.RhinoTestRun based on provided test cases.</returns>
        public override RhinoTestRun OnCreateTestRun(RhinoTestRun testRun)
        {
            // constants: logging
            const string M1 = "test-run [{0}] create under [{1}] project";

            // constants
            const string C1 = "Automatically generated by Rhino engine";

            // shortcuts
            var M = Configuration.Capabilities.GetCapability(Connector.TestRail, "milestone", string.Empty);

            // collect all suites used in this run
            var suites = GetSuites(testRun.TestCases).Distinct();

            // compose information about suits & cases for this run
            var entires     = Get(suites, testRun.TestCases);
            var planEntries = Get(entires);

            // get milestone
            _ = int.TryParse(M, out int msOut);
            var milestone = milestoneClient
                            .GetMileStones(project.Id)
                            .FirstOrDefault(i => i.Id == msOut || i.Name.Equals(M, StringComparison.OrdinalIgnoreCase));

            // create ALM test plan (test run)
            var addPlan = new TestRailPlan
            {
                Description = C1,
                Name        = TestRun.Title,
                Entries     = planEntries.ToArray(),
                MilestoneId = milestone == default ? null : (int?)milestone.Id
            };
            var plan = plansClient.AddPlan(project.Id, addPlan);

            logger?.DebugFormat(M1, plan.Id, project.Name);

            // update connector test-run
            TestRun.Key = $"{plan.Entries[0].Runs[0].Id}";
            TestRun.Context[nameof(TestRailPlan)] = plan;
            return(testRun);
        }
        private void AttachToTestPlan(RhinoTestRun testRun)
        {
            // attach to plan (if any)
            var plans = testRun.TestCases.SelectMany(i => (List <string>)i.Context["testPlans"]).Distinct();

            // exit conditions
            if (!plans.Any())
            {
                return;
            }

            // build commands
            var commands = plans.Select(i => RavenCommandsRepository.AssociateExecutions(i, new[] { testRun.Key }));

            // send
            var options = new ParallelOptions {
                MaxDegreeOfParallelism = BucketSize
            };

            Parallel.ForEach(commands, options, command => jiraExecutor.SendCommand(command));
        }
Exemplo n.º 7
0
        private static void ProcessOutcome(RhinoTestRun outcome)
        {
            // output
            var jsonSettings = Gravity.Extensions.Utilities.GetJsonSettings <CamelCaseNamingStrategy>(Formatting.Indented);

            Console.WriteLine(JsonConvert.SerializeObject(outcome, jsonSettings));

            // constants: logging
            const string M =
                "Total of [{0}] tests failed and stopped the process. Please review your tests results report.";

            // exit conditions
            if (outcome.TotalFail == 0)
            {
                Environment.Exit(0);
            }

            // exit with failure code
            Console.Error.WriteLine(string.Format(M, outcome.TotalFail));
            Environment.Exit(errorCode);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Gets a JiraAuthentication based on the configuration in RhinoTestRun.Context.
 /// </summary>
 /// <param name="testRun">RhinoTestRun to get JiraAuthentication from.</param>
 /// <returns>JiraAuthentication object or empty JiraAuthentication if not found.</returns>
 public static JiraAuthentication GetAuthentication(this RhinoTestRun testRun)
 {
     return(DoGetAuthentication(testRun.Context));
 }