use of hudson.tasks.junit.TestResult in project jenkin-qtest-plugin by QASymphony.
the class PatternScanParser method parse.
/**
* Read test results with test result location pattern
*
* @param request request
* @param testResultLocation testResultLocation
* @return a list of {@link AutomationTestResult}
* @throws Exception Exception
*/
public List<AutomationTestResult> parse(ParseRequest request, String testResultLocation) throws Exception {
JUnitParser jUnitParser = new JUnitParser(true);
Run<?, ?> build = request.getBuild();
Launcher launcher = request.getLauncher();
TaskListener listener = request.getListener();
List<TestResult> testResults = new ArrayList<>();
testResults.add(jUnitParser.parseResult(testResultLocation, build, request.getWorkSpace(), launcher, listener));
GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTimeInMillis(build.getStartTimeInMillis());
return CommonParsingUtils.toAutomationTestResults(request, testResults, gregorianCalendar.getTime());
}
use of hudson.tasks.junit.TestResult in project phabricator-jenkins-plugin by uber.
the class JUnitTestProviderTest method getTestResult.
private TestResult getTestResult() throws IOException {
File temp = File.createTempFile("anything", "xml");
temp.deleteOnExit();
InputStream junit = getClass().getResourceAsStream("go-torch-junit.xml");
IOUtils.copy(junit, temp);
TestResult result = new TestResult();
result.parse(temp);
return result;
}
use of hudson.tasks.junit.TestResult in project jenkin-qtest-plugin by QASymphony.
the class CommonParsingUtils method useTestMethodAsTestCase.
/**
* Each method as a testCase in qTest
*
* @param request parse request
* @param testResults testResults
* @param startTime start build time
* @return
* @throws Exception
*/
private static List<AutomationTestResult> useTestMethodAsTestCase(ParseRequest request, List<TestResult> testResults, Date startTime) throws Exception {
Map<String, AutomationTestResult> map = new HashMap<>();
int currentTestLogOrder = 0;
for (TestResult testResult : testResults) {
for (SuiteResult suite : testResult.getSuites()) {
if (suite.getCases() == null) {
continue;
}
Date startDate = JsonUtils.parseTimestamp(suite.getTimestamp());
startDate = startDate == null ? startTime : startDate;
for (CaseResult caseResult : suite.getCases()) {
String automationContent = caseResult.getClassName() + "#" + caseResult.getName();
if (!map.containsKey(automationContent)) {
AutomationTestResult testLog = new AutomationTestResult();
testLog.setOrder(currentTestLogOrder++);
testLog.setAutomationContent(automationContent);
testLog.setExecutedStartDate(startDate);
testLog.setExecutedEndDate(computeEndTime(startDate, caseResult.getDuration()));
testLog.addTestStepLog(new AutomationTestStepLog(caseResult), request.getOverwriteExistingTestSteps());
if (caseResult.isFailed()) {
try {
AutomationAttachment attachment = new AutomationAttachment(caseResult);
attachment.setData(Base64.encodeBase64String(attachment.getData().getBytes()));
testLog.addAttachment(attachment);
} catch (Exception e) {
LoggerUtils.formatError(request.getListener().getLogger(), "Error while build attachment: %s, %s", e.getMessage(), e.getStackTrace());
}
}
map.put(automationContent, testLog);
}
}
}
}
return new ArrayList<>(map.values());
}
use of hudson.tasks.junit.TestResult in project jenkin-qtest-plugin by QASymphony.
the class CommonParsingUtils method useClassNameAsTestCase.
/**
* Class name as a testCase in qTest
*
* @param request parse request
* @param testResults testResults
* @param startTime start build time
* @return
* @throws Exception
*/
private static List<AutomationTestResult> useClassNameAsTestCase(ParseRequest request, List<TestResult> testResults, Date startTime) throws Exception {
Map<String, AutomationTestResult> map = new HashMap<>();
int currentTestLogOrder = 0;
for (TestResult testResult : testResults) {
for (SuiteResult suite : testResult.getSuites()) {
if (suite.getCases() == null) {
continue;
}
Date startDate = JsonUtils.parseTimestamp(suite.getTimestamp());
startDate = startDate == null ? startTime : startDate;
for (CaseResult caseResult : suite.getCases()) {
AutomationTestResult testLog = null;
if (map.containsKey(caseResult.getClassName())) {
testLog = map.get(caseResult.getClassName());
} else {
testLog = new AutomationTestResult();
testLog.setOrder(currentTestLogOrder++);
testLog.setAutomationContent(caseResult.getClassName());
testLog.setExecutedStartDate(startDate);
testLog.setExecutedEndDate(computeEndTime(startDate, suite.getDuration()));
map.put(caseResult.getClassName(), testLog);
}
testLog.addTestStepLog(new AutomationTestStepLog(caseResult), request.getOverwriteExistingTestSteps());
if (caseResult.isFailed()) {
testLog.addAttachment(new AutomationAttachment(caseResult));
}
}
}
}
map = processAttachment(map);
return new ArrayList<>(map.values());
}
use of hudson.tasks.junit.TestResult in project jenkin-qtest-plugin by QASymphony.
the class PublishResultParser method parse.
@Override
public List<AutomationTestResult> parse(ParseRequest request) throws Exception {
Run<?, ?> build = request.getBuild();
TestResultAction resultAction = build.getAction(TestResultAction.class);
List<TestResult> testResults = new ArrayList<>();
if (resultAction != null) {
testResults.add(resultAction.getResult());
} else {
AggregatedTestResultAction aggregatedTestResultAction = build.getAction(AggregatedTestResultAction.class);
if (aggregatedTestResultAction != null) {
List<ChildReport> childReports = aggregatedTestResultAction.getResult();
if (childReports != null) {
for (ChildReport childReport : childReports) {
if (childReport.result instanceof TestResult) {
testResults.add((TestResult) childReport.result);
}
}
}
} else {
LoggerUtils.formatWarn(request.getListener().getLogger(), "No testResult action was added to project.");
}
}
GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTimeInMillis(build.getStartTimeInMillis());
return CommonParsingUtils.toAutomationTestResults(request, testResults, gregorianCalendar.getTime());
}
Aggregations