/** * 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; }
/** * Construct a FlakyTestResultAction object with AbstractBuild and BuildListener * * @param build this build * @param listener listener of this build */ public FlakyTestResultAction(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { this.build = build; // TODO consider the possibility that there is >1 such action AbstractTestResultAction action = build.getAction(AbstractTestResultAction.class); if (action != null) { Object latestResult = action.getResult(); if (latestResult != null && latestResult instanceof TestResult) { FlakyTestResult flakyTestResult = launcher.getChannel().call(new FlakyTestResultCollector((TestResult) latestResult)); flakyTestResult.freeze(action, build); FlakyRunStats stats = new FlakyRunStats(flakyTestResult.getTestFlakyStatsMap()); setFlakyRunStats(stats, listener); } } else { logger.log(Level.WARNING, "No test result found, please publish junit report first"); } }
public void testNoTestsHaveQuarantineActionForStandardPublisher() throws Exception { project.getPublishersList().remove(QuarantinableJUnitResultArchiver.class); DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> publishers = new DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>>( project); publishers.add(new QuarantineTestDataPublisher()); project.getPublishersList().add(new JUnitResultArchiver("*.xml", false, publishers)); TestResult tr = getResultsFromJUnitResult("junit-1-failure.xml"); for (SuiteResult suite : tr.getSuites()) { for (CaseResult result : suite.getCases()) { assertNull(result.getTestAction(QuarantineTestAction.class)); } } }
public void testQuarantiningMakesFinalResultFailIfQuarantineReleased() throws Exception { FreeStyleBuild build = runBuildWithJUnitResult("junit-1-failure.xml"); assertTrue(build.getResult() != Result.SUCCESS); TestResult tr = build.getAction(TestResultAction.class).getResult(); QuarantineTestAction action = tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class); action.quarantine("user1", "reason"); build = runBuildWithJUnitResult("junit-1-failure.xml"); assertTrue(build.getResult() == Result.SUCCESS); tr = build.getAction(TestResultAction.class).getResult(); action = tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class); action.release(); build = runBuildWithJUnitResult("junit-1-failure.xml"); System.out.println("result is " + build.getResult()); assertTrue(build.getResult() != Result.SUCCESS); }
public void testQuarantineReportGetNumberOfSuccessivePasses() throws Exception { TestResult tr = getResultsFromJUnitResult("junit-no-failure.xml"); tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class).quarantine("user1", "reason"); QuarantinedTestsReport report = new QuarantinedTestsReport(); assertEquals(1, report.getNumberOfSuccessivePasses(report.getQuarantinedTests().get(0))); runBuildWithJUnitResult("junit-no-failure.xml"); report = new QuarantinedTestsReport(); assertEquals(2, report.getNumberOfSuccessivePasses(report.getQuarantinedTests().get(0))); runBuildWithJUnitResult("junit-1-failure.xml"); report = new QuarantinedTestsReport(); assertEquals(0, report.getNumberOfSuccessivePasses(report.getQuarantinedTests().get(0))); runBuildWithJUnitResult("junit-no-failure.xml"); report = new QuarantinedTestsReport(); assertEquals(1, report.getNumberOfSuccessivePasses(report.getQuarantinedTests().get(0))); }
@Override public TestResultAction.Data contributeTestData(Run<?, ?> run, @Nonnull FilePath workspace, Launcher launcher, TaskListener listener, TestResult testResult) throws IOException, InterruptedException { log(listener.getLogger(), "Publishing test results"); Map<String, String> testSessionMap = workspace.act(new BrowserStackReportFileCallable(REPORT_FILE_PATTERN, run.getTimeInMillis())); AutomateActionData automateActionData = new AutomateActionData(); Map<String, Long> testCaseIndices = new HashMap<String, Long>(); int testCount = 0; int sessionCount = 0; for (SuiteResult suiteResult : testResult.getSuites()) { List<CaseResult> cases = suiteResult.getCases(); testCount += cases.size(); logDebug(listener.getLogger(), suiteResult.getName() + ": " + cases.size() + " test cases found."); for (CaseResult caseResult : cases) { String testCaseName = getTestCaseName(caseResult); Long testIndex = testCaseIndices.containsKey(testCaseName) ? testCaseIndices.get(testCaseName) : -1L; testCaseIndices.put(testCaseName, ++testIndex); logDebug(listener.getLogger(), testCaseName + " / " + testCaseName + " <=> " + testIndex); String testId = String.format("%s{%d}", testCaseName, testIndex); if (testSessionMap.containsKey(testId)) { AutomateTestAction automateTestAction = new AutomateTestAction(run, caseResult, testSessionMap.get(testId)); automateActionData.registerTestAction(caseResult.getId(), automateTestAction); logDebug(listener.getLogger(), "registerTestAction: " + testId + " => " + automateTestAction); sessionCount++; } } } testCaseIndices.clear(); log(listener.getLogger(), testCount + " tests recorded"); log(listener.getLogger(), sessionCount + " sessions captured"); log(listener.getLogger(), "Publishing test results: SUCCESS"); return automateActionData; }
private TestResult getJUnitResults() { AbstractBuild build = getBuild(); TestResultAction jUnitAction = build.getAction(TestResultAction.class); if (jUnitAction == null) { return null; } return jUnitAction.getResult(); }
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; }
/** * Get display names for all the test cases * * @param results Collection of {@link hudson.tasks.junit.TestResult} objects * @return the set of display names for all the test cases */ public static Set<String> getTestIdFromTestResults( Collection<? extends hudson.tasks.test.TestResult> results) { Set<String> testIdSet = new HashSet<String>(); for (hudson.tasks.test.TestResult testResult : results) { if (testResult instanceof FlakyCaseResult) { testIdSet.add(((FlakyCaseResult)testResult).getFullDisplayName()); } } return testIdSet; }
@Override public TestResultAction.Data getTestData(AbstractBuild<?, ?> abstractBuild, Launcher launcher, BuildListener buildListener, TestResult testResult) throws IOException, InterruptedException { FlakyTestResult flakyTestResult = launcher.getChannel().call(new FlakyTestResultCollector(testResult)); // TODO consider the possibility that there is >1 such action flakyTestResult.freeze(abstractBuild.getAction(AbstractTestResultAction.class), abstractBuild); return new JUnitFlakyTestData(flakyTestResult); }
public hudson.tasks.test.TestResult getResultForTestId(String testObjectId) { TestResultAction action = build.getAction(TestResultAction.class); if (action != null && action.getResult() != null) { return action.getResult().findCorrespondingResult(testObjectId); } return null; }
public void testTextSummaryForUnquarantinedTestAuthenticated() throws Exception { FreeStyleBuild build = runBuildWithJUnitResult("junit-1-failure.xml"); TestResult tr = build.getAction(TestResultAction.class).getResult(); HtmlPage page = whenNavigatingToTestCase(tr.getSuite("SuiteA").getCase("TestA"), true); assertTrue(pageShowsText(page, "This test was not quarantined. Quarantine it.")); }
public void testTextSummaryForUnquarantinedTestNotAuthenticated() throws Exception { FreeStyleBuild build = runBuildWithJUnitResult("junit-1-failure.xml"); TestResult tr = build.getAction(TestResultAction.class).getResult(); HtmlPage page = whenNavigatingToTestCase(tr.getSuite("SuiteA").getCase("TestA"), false); assertTrue(pageShowsText(page, "This test was not quarantined.")); assertFalse(pageShowsText(page, "Quarantine it.")); }
public void testWhenQuarantiningTestSaysQuarantinedBy() throws Exception { FreeStyleBuild build = runBuildWithJUnitResult("junit-1-failure.xml"); TestResult tr = build.getAction(TestResultAction.class).getResult(); HtmlPage page = whenNavigatingToTestCase(tr.getSuite("SuiteA").getCase("TestA"), true); whenQuarantiningTestOnPage(page); page = whenNavigatingToTestCase(tr.getSuite("SuiteA").getCase("TestA"), false); assertTrue(pageShowsText(page, "This test was quarantined by user1")); }
public void testAllTestsHaveQuarantineAction() throws Exception { TestResult tr = getResultsFromJUnitResult("junit-1-failure.xml"); for (SuiteResult suite : tr.getSuites()) { for (CaseResult result : suite.getCases()) { assertNotNull(result.getTestAction(QuarantineTestAction.class)); } } }
public void testQuarantineSetAndRelease() throws Exception { TestResult tr = getResultsFromJUnitResult("junit-1-failure.xml"); QuarantineTestAction action = tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class); action.quarantine("user1", "reason"); assertTrue(action.isQuarantined()); action.release(); assertFalse(action.isQuarantined()); }
public void testQuarantineIsStickyOnFailingTest() throws Exception { TestResult tr = getResultsFromJUnitResult("junit-1-failure.xml"); QuarantineTestAction action = tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class); action.quarantine("user1", "reason"); assertTrue(action.isQuarantined()); tr = getResultsFromJUnitResult("junit-1-failure.xml"); QuarantineTestAction action2 = tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class); assertTrue(tr.getOwner().getNumber() == 2); assertTrue(action2.isQuarantined()); assertEquals(action.quarantinedByName(), action2.quarantinedByName()); }
public void testQuarantineIsStickyOnPassingTest() throws Exception { TestResult tr = getResultsFromJUnitResult("junit-1-failure.xml"); QuarantineTestAction action = tr.getSuite("SuiteA").getCase("TestA").getTestAction(QuarantineTestAction.class); action.quarantine("user1", "reason"); assertTrue(action.isQuarantined()); tr = getResultsFromJUnitResult("junit-1-failure.xml"); QuarantineTestAction action2 = tr.getSuite("SuiteA").getCase("TestA").getTestAction(QuarantineTestAction.class); assertTrue(tr.getOwner().getNumber() == 2); assertTrue(action2.isQuarantined()); assertEquals(action.quarantinedByName(), action2.quarantinedByName()); }
public void testResultIsOnlyMarkedAsLatestIfLatest() throws Exception { FreeStyleBuild build = runBuildWithJUnitResult("junit-1-failure.xml"); TestResult tr1 = build.getAction(TestResultAction.class).getResult(); QuarantineTestAction action1 = tr1.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class); assertTrue(action1.isLatestResult()); build = runBuildWithJUnitResult("junit-1-failure.xml"); TestResult tr2 = build.getAction(TestResultAction.class).getResult(); QuarantineTestAction action2 = tr2.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class); assertFalse(action1.isLatestResult()); assertTrue(action2.isLatestResult()); }
public void testQuarantiningMakesFinalResultPass() throws Exception { FreeStyleBuild build = runBuildWithJUnitResult("junit-1-failure.xml"); assertTrue(build.getResult() != Result.SUCCESS); TestResult tr = build.getAction(TestResultAction.class).getResult(); QuarantineTestAction action = tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class); action.quarantine("user1", "reason"); build = runBuildWithJUnitResult("junit-1-failure.xml"); assertTrue(build.getResult() == Result.SUCCESS); }
public void testQuarantiningMakesFinalResultFailIfAnotherTestFails() throws Exception { FreeStyleBuild build = runBuildWithJUnitResult("junit-1-failure.xml"); assertTrue(build.getResult() != Result.SUCCESS); TestResult tr = build.getAction(TestResultAction.class).getResult(); QuarantineTestAction action = tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class); action.quarantine("user1", "reason"); build = runBuildWithJUnitResult("junit-2-failures.xml"); assertTrue(build.getResult() != Result.SUCCESS); }
public void testQuarantineStatusNotLostIfTestNotRun() throws Exception { FreeStyleBuild build = runBuildWithJUnitResult("junit-1-failure.xml"); assertTrue(build.getResult() != Result.SUCCESS); TestResult tr = build.getAction(TestResultAction.class).getResult(); QuarantineTestAction action = tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class); action.quarantine("user1", "reason"); build = runBuildWithJUnitResult("junit-1-failure-missing.xml"); assertTrue(build.getResult() == Result.SUCCESS); build = runBuildWithJUnitResult("junit-1-failure.xml"); assertTrue(build.getResult() == Result.SUCCESS); }
public void testQuarantinedTestsAreInReport() throws Exception { TestResult tr = getResultsFromJUnitResult("junit-1-failure.xml"); tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class).quarantine("user1", "reason"); tr.getSuite("SuiteB").getCase("TestA").getTestAction(QuarantineTestAction.class).quarantine("user1", "reason"); QuarantinedTestsReport report = new QuarantinedTestsReport(); assertEquals(2, report.getQuarantinedTests().size()); assertTrue(report.getQuarantinedTests().contains(tr.getSuite("SuiteA").getCase("TestB"))); assertTrue(report.getQuarantinedTests().contains(tr.getSuite("SuiteB").getCase("TestA"))); }
public void testSendsEmailWhenQuarantinedFails() throws Exception { Mailbox.clearAll(); TestResult tr = getResultsFromJUnitResult("junit-1-failure.xml"); tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class).quarantine("user1", "reason"); getResultsFromJUnitResult("junit-1-failure.xml"); List<Message> inbox = Mailbox.get(user1Mail); assertEquals(1, inbox.size()); }
public void testDoesntEmailWhenQuarantinedPasses() throws Exception { Mailbox.clearAll(); TestResult tr = getResultsFromJUnitResult("junit-1-failure.xml"); tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class).quarantine("user1", "reason"); getResultsFromJUnitResult("junit-no-failure.xml"); List<Message> inbox = Mailbox.get(user1Mail); assertEquals(0, inbox.size()); }
public void testTestEmailsAreCollatedWhenMultipleQuarantinedFail() throws Exception { Mailbox.clearAll(); TestResult tr = getResultsFromJUnitResult("junit-1-failure.xml"); tr.getSuite("SuiteA").getCase("TestB").getTestAction(QuarantineTestAction.class).quarantine("user1", "reason"); tr.getSuite("SuiteB").getCase("TestA").getTestAction(QuarantineTestAction.class).quarantine("user1", "reason"); getResultsFromJUnitResult("junit-2-failures.xml"); List<Message> inbox = Mailbox.get(user1Mail); assertEquals(1, inbox.size()); }
@Override public String evaluate(Run<?, ?> run, FilePath filePath, TaskListener listener, String testResultFile) throws MacroEvaluationException, IOException, InterruptedException { StringBuilder buffer = new StringBuilder(); TestResult testResult = new TestResult(); File junitFile = new File(testResultFile); testResult.parse(junitFile); SuiteResult suite = testResult.getSuites().iterator().next(); int failCount = getFailedTestCount(suite); if (null == testResult) { return "No tests ran."; } if (failCount == 0) { buffer.append("All tests passed"); } else { buffer.append(failCount).append(" tests failed.\n"); boolean showOldFailures = !onlyRegressions; // if(maxLength < Integer.MAX_VALUE) { // maxLength *= 1024; // } if (maxTests > 0) { int printedTests = 0; int printedLength = 0; List<CaseResult> cases = suite.getCases(); for (CaseResult caseResult : cases) { if (!caseResult.isPassed() && !caseResult.isSkipped() && caseResult.getErrorDetails() != null) { // Any error, invalidates the suite result if (showOldFailures || getTestAge(caseResult) == 1) { if (printedTests < maxTests && printedLength <= maxLength) { printedLength += outputTest(buffer, caseResult, showStack, showMessage, maxLength - printedLength); printedTests++; } } } } if (failCount > printedTests) { buffer.append("... and ").append(failCount - printedTests).append(" other failed tests.\n\n"); } if (printedLength >= maxLength) { buffer.append("\n\n... output truncated.\n\n"); } } } return buffer.toString(); }
@Override public TestResultAction.Data getTestData(AbstractBuild<?, ?> abstractBuild, Launcher launcher, BuildListener buildListener, TestResult testResult) throws IOException, InterruptedException { return contributeTestData(abstractBuild, abstractBuild.getWorkspace(), launcher, buildListener, testResult); }
public FlakyTestResultCollector(TestResult testResult) { this.testResult = testResult; }
@Override public hudson.tasks.test.TestResult findCorrespondingResult(String id) { return testResultInstance.findCorrespondingResult(id); }
public FailingTestResultAction() { super(new TestResult(), new StreamBuildListener(System.out)); }
@Override public synchronized void setResult(TestResult result, BuildListener listener) { }
@Override public Data getTestData(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, TestResult testResult) throws IOException, InterruptedException { return new SahaginTestData(build); }
@Override public Data getTestData(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, TestResult testResult) { Data data = new Data(build); MailNotifier notifier = new MailNotifier(listener); for (SuiteResult suite : testResult.getSuites()) { for (CaseResult result : suite.getCases()) { QuarantineTestAction previousAction = null; CaseResult previous = result.getPreviousResult(); AbstractBuild<?, ?> previousBuild = build.getPreviousCompletedBuild(); if (previous != null) { previousAction = previous.getTestAction(QuarantineTestAction.class); } // no immediate predecessor (e.g. because job failed or did not // run), try and go back in build history while (previous == null && previousBuild != null) { if (previousBuild.getAction(AbstractTestResultAction.class) != null) { hudson.tasks.test.TestResult tr = null; try { tr = previousBuild.getAction(AbstractTestResultAction.class).findCorrespondingResult( result.getId()); } catch (Exception e){ listener.getLogger().println("could not find result for id " + result.getId() + " in build " + previousBuild + ": " + e.getMessage()); } if (tr != null) { listener.getLogger().println("found " + tr.getDisplayName() + " in build " + previousBuild); previousAction = tr.getTestAction(QuarantineTestAction.class); break; } } else { listener.getLogger().println("build " + previousBuild + " does not have test results"); } previousBuild = previousBuild.getPreviousCompletedBuild(); } if (previousAction != null && previousAction.isQuarantined()) { QuarantineTestAction action = new QuarantineTestAction(data, result.getId()); action.quarantine(previousAction); data.addQuarantine(result.getId(), action); // send email if failed if (!result.isPassed()) { notifier.addResult(result, action); } } } } notifier.sendEmails(); return data; }
protected TestResult getResultsFromJUnitResult(final String xmlFileName) throws Exception { return runBuildWithJUnitResult(xmlFileName).getAction(TestResultAction.class).getResult(); }
/** * Gets the "children" of this test result that passed * * @return the children of this test result, if any, or an empty collection */ @Override public Collection<? extends hudson.tasks.test.TestResult> getPassedTests() { return passedTests; }