public static int reportTests(BuildContext context, String filePattern) throws IOException, InterruptedException { context.listener.getLogger().println("Recording test results matching: '" + filePattern + "'"); final Result resultBefore = context.build.getResult(); JUnitResultArchiver task = new JUnitResultArchiver(filePattern, true, null, 1.0); task.perform(context.build, context.launcher, context.listener); final Result resultAfter = context.build.getResult(); final int testCount; TestResultAction testResultAction = context.build.getAction(TestResultAction.class); if (testResultAction != null) { testCount = testResultAction.getTotalCount(); } else { testCount = -1; } context.listener.getLogger().println(" Test results reported " + testCount + " tests. Status: " + resultAfter); if (isResultWorse(resultBefore, resultAfter)) { context.listener.getLogger().println(" Test results changed build status to " + resultAfter); } return testCount; }
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)); } } }
@Test public void testThatReportsArePresent() throws Exception { /* =================== Prepare ================= */ new MockAutomateClient(); addBuildStep(); project.getBuildersList().add(new TouchBuilder()); project.getBuildersList().add(new CopyResourceFileToWorkspaceTarget("browserstack-reports", "REPORT-com.browserstack.automate.application.tests.TestCaseWithFourUniqueSessions.xml")); project.getBuildersList().add(new CopyResourceFileToWorkspaceTarget("surefire-reports", "TEST-com.browserstack.automate.application.tests.TestCaseWithFourUniqueSessions.xml")); JUnitResultArchiver jUnitResultArchiver = new JUnitResultArchiver("**/surefire-reports/*.xml"); jUnitResultArchiver.setTestDataPublishers(Collections.singletonList(new AutomateTestDataPublisher())); project.getPublishersList().add(jUnitResultArchiver); /* =================== Execute ================= */ FreeStyleBuild build = project.scheduleBuild2(0).get(); TestResultAction action = build.getAction(TestResultAction.class); /* =================== Verify ================= */ List<TestResultAction.Data> testData = Deencapsulation.getField(action, "testData"); // Assumption here is that there is only one suite result based on the XML files // copied into the workspace above. SuiteResult suiteResult = action.getResult().getSuites().iterator().next(); jenkinsRule.assertBuildStatus(Result.SUCCESS, build); Assert.assertNotNull("Additional data on the test MUST be set.", testData); Assert.assertTrue("Additional Test data MUST have values.", testData.size() >= 1); TestResultAction.Data data = testData.get(0); Assert.assertTrue("Additional Test data MUST be an instance of AutomateActionData.", data instanceof AutomateActionData); for (CaseResult caseResult : suiteResult.getCases()) { AutomateTestAction automateTestAction = (AutomateTestAction) data.getTestAction(caseResult).get(0); Session automateSession = automateTestAction.getSession(); Assert.assertNotNull("Automate Session should not be null.", automateSession); Assert.assertTrue("Session Id should not be null or empty.", StringUtils.isNotEmpty(automateSession.getId())); } }
@Override public boolean perform(DynamicBuild dynamicBuild, Launcher launcher, BuildListener listener) { String files = getPluginInputFiles(); listener.getLogger().println(String.format("Archiving JUnit results: '%s'", files)); DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers = new DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>>(Saveable.NOOP); JUnitResultArchiver publisher = new JUnitResultArchiver(files, true, testDataPublishers); try { return publisher.perform(((AbstractBuild) dynamicBuild), launcher, listener); } catch (Exception e) { listener.getLogger().println(String.format("FAILED archiving JUnit results: %s", e.toString())); return false; } }
@Test public void coreStepWithSymbol() throws Exception { JUnitResultArchiver aa = new JUnitResultArchiver("target/surefire/*.xml"); aa.setAllowEmptyResults(true); st.assertRoundTrip(new CoreStep(aa), "junit allowEmptyResults: true, testResults: 'target/surefire/*.xml'"); }
@Test public void coreStepWithSymbolWithSoleArg() throws Exception { JUnitResultArchiver aa = new JUnitResultArchiver("target/surefire/*.xml"); st.assertRoundTrip(new CoreStep(aa), "junit 'target/surefire/*.xml'"); }
public static Publisher getDefaultXUnitPublisher() { return new JUnitResultArchiver( JUNIT_XML ); }