Search in sources :

Example 1 with AutomationTestStepLog

use of com.qasymphony.ci.plugin.model.AutomationTestStepLog in project jenkin-qtest-plugin by QASymphony.

the class MavenJunitParseTests method testParseMavenProject.

@LocalData
@Test
public void testParseMavenProject() throws InterruptedException, ExecutionException, TimeoutException, IOException {
    project = j.createFreeStyleProject("maven-project");
    automationTestResultList = null;
    project.getBuildersList().add(new MavenParseTestMavenProject());
    FreeStyleBuild build = project.scheduleBuild2(0).get(100, TimeUnit.MINUTES);
    assertNotNull("Build is: ", build);
    assertEquals("", 8, automationTestResultList.size());
    AutomationTestResult calculateTest = null;
    for (AutomationTestResult automationTestResult : automationTestResultList) {
        if (automationTestResult.getName().equalsIgnoreCase("sample.junit.CalculateTest")) {
            calculateTest = automationTestResult;
            break;
        }
    }
    assertNotNull("Calculate test is:", calculateTest);
    assertEquals("Test log size is ", 4, calculateTest.getTestLogs().size());
    AutomationTestStepLog first = calculateTest.getTestLogs().get(0);
    assertEquals("Description 1 is ", "testSum_second", first.getDescription());
    assertEquals("Status 1 is ", "FAILED", first.getStatus());
    AutomationTestStepLog second = calculateTest.getTestLogs().get(1);
    assertEquals("Description 2 is ", "testSum_one", second.getDescription());
    assertEquals("Status 2 is ", "PASSED", second.getStatus());
}
Also used : AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) AutomationTestStepLog(com.qasymphony.ci.plugin.model.AutomationTestStepLog) FreeStyleBuild(hudson.model.FreeStyleBuild) LocalData(org.jvnet.hudson.test.recipes.LocalData) Test(org.junit.Test)

Example 2 with AutomationTestStepLog

use of com.qasymphony.ci.plugin.model.AutomationTestStepLog 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 3 with AutomationTestStepLog

use of com.qasymphony.ci.plugin.model.AutomationTestStepLog 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)

Aggregations

AutomationTestResult (com.qasymphony.ci.plugin.model.AutomationTestResult)3 AutomationTestStepLog (com.qasymphony.ci.plugin.model.AutomationTestStepLog)3 AutomationAttachment (com.qasymphony.ci.plugin.model.AutomationAttachment)2 CaseResult (hudson.tasks.junit.CaseResult)2 SuiteResult (hudson.tasks.junit.SuiteResult)2 TestResult (hudson.tasks.junit.TestResult)2 FreeStyleBuild (hudson.model.FreeStyleBuild)1 Test (org.junit.Test)1 LocalData (org.jvnet.hudson.test.recipes.LocalData)1