Search in sources :

Example 1 with SuiteResult

use of hudson.tasks.junit.SuiteResult 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());
}
Also used : AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) AutomationTestStepLog(com.qasymphony.ci.plugin.model.AutomationTestStepLog) TestResult(hudson.tasks.junit.TestResult) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) SuiteResult(hudson.tasks.junit.SuiteResult) AutomationAttachment(com.qasymphony.ci.plugin.model.AutomationAttachment) CaseResult(hudson.tasks.junit.CaseResult)

Example 2 with SuiteResult

use of hudson.tasks.junit.SuiteResult 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());
}
Also used : AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) AutomationAttachment(com.qasymphony.ci.plugin.model.AutomationAttachment) AutomationTestStepLog(com.qasymphony.ci.plugin.model.AutomationTestStepLog) CaseResult(hudson.tasks.junit.CaseResult) TestResult(hudson.tasks.junit.TestResult) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) SuiteResult(hudson.tasks.junit.SuiteResult)

Example 3 with SuiteResult

use of hudson.tasks.junit.SuiteResult in project phabricator-jenkins-plugin by uber.

the class JUnitTestProvider method convertJUnit.

/**
 * Convert JUnit's TestResult representation into a generic UnitResults
 *
 * @param jUnitResults The result of the JUnit run
 * @return The converted results
 */
public UnitResults convertJUnit(TestResult jUnitResults) {
    UnitResults results = new UnitResults();
    if (jUnitResults == null) {
        return results;
    }
    for (SuiteResult sr : jUnitResults.getSuites()) {
        for (CaseResult cr : sr.getCases()) {
            UnitResult result = new UnitResult(cr.getClassName(), cr.getDisplayName(), cr.getErrorStackTrace(), cr.getDuration(), cr.getFailCount(), cr.getSkipCount(), cr.getPassCount());
            results.add(result);
        }
    }
    return results;
}
Also used : CaseResult(hudson.tasks.junit.CaseResult) SuiteResult(hudson.tasks.junit.SuiteResult)

Aggregations

CaseResult (hudson.tasks.junit.CaseResult)3 SuiteResult (hudson.tasks.junit.SuiteResult)3 AutomationAttachment (com.qasymphony.ci.plugin.model.AutomationAttachment)2 AutomationTestResult (com.qasymphony.ci.plugin.model.AutomationTestResult)2 AutomationTestStepLog (com.qasymphony.ci.plugin.model.AutomationTestStepLog)2 TestResult (hudson.tasks.junit.TestResult)2