private List <TestInformationReportDTO> GetSpecflowTestesToReport(TestResultContentFile trxObj) { var testList = new List <TestInformationReportDTO>(); if (trxObj != null) { var specFlowTest = trxObj.Results.Where(x => x.Output != null && !string.IsNullOrEmpty(x.Output.StdOut) && (x.Output.StdOut.IndexOf(ExtendReportConsts.Given) == 0 || x.Output.StdOut.IndexOf(ExtendReportConsts.Dado) == 0)).ToList(); specFlowTest.ForEach(t => { try { if (!string.IsNullOrEmpty(t.TestName)) { var scenarioName = GetSpecScenarioName(t.TestName); var executationId = t.ExecutionId; var testDefinition = trxObj.TestDefinitions.Where(x => x.Execution.Id == executationId).FirstOrDefault(); if (testDefinition != null) { var featureName = GetSpecFeatureName(testDefinition.TestMethod.ClassName); var listaSteps = new List <TestStepDTO>(); var rawStdOutRows = t.Output.StdOut.Split(Environment.NewLine); var lastStepType = string.Empty; for (var i = 0; i < rawStdOutRows.Length; i += 2) { var stepInfo = rawStdOutRows[i]; var stepResult = rawStdOutRows[i + 1]; var stepName = stepInfo; var currentStepType = stepInfo.Split(" ")[0]; var stepTypeToUse = GetStepTypeWord(currentStepType, lastStepType); lastStepType = stepTypeToUse; var gherkinStep = GetStepGherkinKeyword(stepTypeToUse); var step = new TestStepDTO(gherkinStep) { Name = stepName, Description = stepName, EndTime = t.EndTime, StartTime = t.StartTime, Error = GetErrorInStep(t, stepResult) }; listaSteps.Add(step); } AddTestToReport(false, featureName, scenarioName, listaSteps, testList); } } } catch (Exception e) { _logger.LogError(e, $"Erro ao processar o teste SPEC {t.TestName}"); } }); } return(testList); }
private TestResultContentFile GetTesteResultContentFile(string trxFile) { TestResultContentFile trxObj = null; var fileContent = File.ReadAllText(trxFile); using (var stringReader = new StringReader(fileContent)) { var serializer = new XmlSerializer(typeof(TestResultContentFile)); trxObj = (TestResultContentFile)serializer.Deserialize(stringReader); } return(trxObj); }
private List <TestInformationReportDTO> GetUnitTestesToReport(TestResultContentFile trxInformation) { var testList = new List <TestInformationReportDTO>(); if (trxInformation != null) { var unitTests = trxInformation.Results.Where(x => x.Output == null || (x.Output.StdOut == null)).ToList(); unitTests.ForEach(t => { try { if (!string.IsNullOrEmpty(t.TestName)) { var splitedTestName = t.TestName.Split("."); var stepName = splitedTestName[splitedTestName.Length - 1]; var scenarioName = splitedTestName[splitedTestName.Length - 2]; var featureName = t.TestName.Replace($".{scenarioName}.{stepName}", string.Empty); var step = new TestStepDTO() { Name = stepName, Description = stepName, EndTime = t.EndTime, StartTime = t.StartTime, Error = GetErrorInStep(t) }; AddTestToReport(true, featureName, scenarioName, new List <TestStepDTO> { step }, testList); } } catch (Exception e) { _logger.LogError(e, $"Erro ao processar o teste UNITÁRIO {t.TestName}"); } }); } return(testList); }