public void AfterEach(ISpecContext context)
        {
            SpecContext ctx = (SpecContext)context;

            if (TestRailRunContext.Current != null)
            {
                foreach (int testCaseId in TestCaseParser.ParseTestCaseIds(ctx.Specification.name))
                {
                    var addResultRequest = new AddResultRequest
                    {
                        status_id = (int)(ctx.Counts.Exceptions > 0 || ctx.Counts.Wrongs > 0
                                                        ? TestResultStatus.Failed
                                                        : TestResultStatus.Passed),
                        case_id = testCaseId,
                        run_id  = TestRailRunContext.Current.RunId
                    };

                    try
                    {
                        var response = _client.AddTestCaseTestRunResult(addResultRequest);
                        context.Reporting.Log("TestRail", $"<div>{response}</div>");
                    }
                    catch (Exception ex)
                    {
                        context.Reporting.Log("TestRail", $"<div>{ex}</div>");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Receive(BatchRunRequest message)
        {
            int[] testCaseIds = message.Specifications.SelectMany(spec => TestCaseParser.ParseTestCaseIds(spec.name))
                                .Union(message.Specifications.SelectMany(spec => spec.Tags?.SelectMany(TestCaseParser.ParseTestCaseIds)))
                                .ToArray();

            if (!testCaseIds.Any())
            {
                Console.WriteLine("No TestRail Test Case IDs found in specifications. No Test Run will be created.");
                return;
            }

            AddRunResponse testRunResult = _client.AddTestRun(new AddRunRequest
            {
                project_id  = _testRailRunLoggerSettings.ProjectId,
                name        = _testRailRunLoggerSettings.TestRailRunNameGenerator.Generate(),
                case_ids    = testCaseIds,
                description = "Generated from StoryTeller"
            });

            TestRailRunContext.Create(testRunResult.id);

            Console.WriteLine(testRunResult);
        }