Search in sources :

Example 1 with TestResult

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());
}
Also used : TaskListener(hudson.model.TaskListener) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) JUnitParser(hudson.tasks.junit.JUnitParser) Launcher(hudson.Launcher) TestResult(hudson.tasks.junit.TestResult) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult)

Example 2 with TestResult

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;
}
Also used : InputStream(java.io.InputStream) TestResult(hudson.tasks.junit.TestResult) File(java.io.File)

Example 3 with TestResult

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());
}
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 4 with TestResult

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());
}
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 5 with TestResult

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());
}
Also used : AggregatedTestResultAction(hudson.tasks.test.AggregatedTestResultAction) ChildReport(hudson.tasks.test.AggregatedTestResultAction.ChildReport) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) TestResult(hudson.tasks.junit.TestResult) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) TestResultAction(hudson.tasks.junit.TestResultAction) AggregatedTestResultAction(hudson.tasks.test.AggregatedTestResultAction)

Aggregations

TestResult (hudson.tasks.junit.TestResult)5 AutomationTestResult (com.qasymphony.ci.plugin.model.AutomationTestResult)4 AutomationAttachment (com.qasymphony.ci.plugin.model.AutomationAttachment)2 AutomationTestStepLog (com.qasymphony.ci.plugin.model.AutomationTestStepLog)2 CaseResult (hudson.tasks.junit.CaseResult)2 SuiteResult (hudson.tasks.junit.SuiteResult)2 ArrayList (java.util.ArrayList)2 GregorianCalendar (java.util.GregorianCalendar)2 Launcher (hudson.Launcher)1 TaskListener (hudson.model.TaskListener)1 JUnitParser (hudson.tasks.junit.JUnitParser)1 TestResultAction (hudson.tasks.junit.TestResultAction)1 AggregatedTestResultAction (hudson.tasks.test.AggregatedTestResultAction)1 ChildReport (hudson.tasks.test.AggregatedTestResultAction.ChildReport)1 File (java.io.File)1 InputStream (java.io.InputStream)1