Java Examples for hudson.tasks.junit.JUnitResultArchiver

The following java examples will help you to understand the usage of hudson.tasks.junit.JUnitResultArchiver. These source code samples are taken from different open source projects.

Example 1
Project: hudson_plugins-master  File: GrailsProjectCrawlerTask.java View source code
protected void setupJob(FreeStyleProject job, GrailsProjectInfo info) throws Exception {
    job.setDescription(descriptionTemplate.generate(info));
    job.setLogRotator(new LogRotator(-1, 3));
    job.addTrigger(new SCMTrigger("*/5 * * * *"));
    job.setAssignedLabel(null);
    addGBuildWrapper(job);
    DescribableList<Builder, Descriptor<Builder>> builders = job.getBuildersList();
    builders.clear();
    builders.add(new Shell(JOB_SHELL.generate(info)));
    String targets = "clean " + (info.isTestsAvirable() ? "test-app" : "package") + " --non-interactive";
    builders.add(new GrailsBuilder(targets, context.getGrailsMap().get(info.getGrailsVersion()), null, null, null, null));
    DescribableList<Publisher, Descriptor<Publisher>> publishers = job.getPublishersList();
    publishers.clear();
    if (info.isTestsAvirable()) {
        publishers.add(new JUnitResultArchiver(format("%s/test/reports/TEST*.xml", info.getName()), null));
    }
    if (isActive("emotional-hudson")) {
        publishers.add(createEmotionalHudsonPublisher());
    }
    if (isActive("twitter")) {
        publishers.add(createTwitterPublisher());
    }
}
Example 2
Project: jenkins-plugins-master  File: OnlyRegressionsTest.java View source code
@Test
public void testOnlyRegressionsAreShown() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject("onlyRegressions");
    project.getPublishersList().add(new JUnitResultArchiver("target/testreports/*.xml", true, null));
    project.getBuildersList().add(new TestBuilder() {

        @Override
        public boolean perform(AbstractBuild<?, ?> abstractBuild, Launcher launcher, BuildListener buildListener) throws InterruptedException, IOException {
            final URL failedTestReport = Thread.currentThread().getContextClassLoader().getResource("hudson/plugins/emailext/testreports/failed_test.xml");
            FilePath workspace = abstractBuild.getWorkspace();
            FilePath testDir = workspace.child("target").child("testreports");
            testDir.mkdirs();
            FilePath reportFile = testDir.child("failed_test.xml");
            reportFile.copyFrom(failedTestReport);
            return true;
        }
    });
    TaskListener listener = StreamTaskListener.fromStdout();
    project.scheduleBuild2(0).get();
    FailedTestsContent failedTestsContent = new FailedTestsContent();
    failedTestsContent.onlyRegressions = true;
    String content = failedTestsContent.evaluate(project.getLastBuild(), listener, FailedTestsContent.MACRO_NAME);
    assertTrue("The failing test should be reported the first time it fails", content.contains("hudson.plugins.emailext"));
    project.scheduleBuild2(0).get();
    content = failedTestsContent.evaluate(project.getLastBuild(), listener, FailedTestsContent.MACRO_NAME);
    assertFalse("The failing test should not be reported the second time it fails", content.contains("hudson.plugins.emailext"));
    assertTrue("The content should state that there are other failing tests still", content.contains("and 1 other failed test"));
}
Example 3
Project: DotCi-Plugins-Starter-Pack-master  File: JunitPluginAdapter.java View source code
@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;
    }
}
Example 4
Project: hudson.test.ui-master  File: CascadingProjectTest.java View source code
/**
     * Tests whether assigning of 'Publish JUnit test result report' option falls through cascading hierarchy.
     */
@Test
public void testCascadingInheritance() {
    prepareCascading("parent", "child1");
    selenium.click(CONFIG_SAVE_BUTTON_EXP);
    selenium.open("/");
    waitForTextPresent("New Job");
    selenium.click("link=New Job");
    selenium.type("name", "child2");
    selenium.click("mode");
    selenium.click("//button[@type='button']");
    selenium.waitForPageToLoad("30000");
    selenium.select("//select[@name='cascadingProjectName']", "child1");
    selenium.waitForPageToLoad("30000");
    selenium.click(CONFIG_SAVE_BUTTON_EXP);
    selenium.open("/job/parent/configure");
    selenium.waitForPageToLoad("30000");
    selenium.click("//input[@name='hudson-tasks-junit-JUnitResultArchiver']");
    selenium.type("//input[@name='_.testResults']", "**/target/surefire-reports/*.xml");
    selenium.click(CONFIG_SAVE_BUTTON_EXP);
    selenium.open("/job/child2/configure");
    selenium.waitForPageToLoad("30000");
    assertEquals("**/target/surefire-reports/*.xml", selenium.getValue("//input[@name='_.testResults']"));
}
Example 5
Project: cloudtest-plugin-master  File: TestCompositionRunner.java View source code
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    // Create a unique sub-directory to store all test results.
    String resultsDir = "." + getClass().getName();
    // Split by newline.
    EnvVars envs = build.getEnvironment(listener);
    String[] compositions = envs.expand(this.composition).split("[\r\n]+");
    String additionalOptionsExpanded = additionalOptions == null ? null : envs.expand(additionalOptions);
    String[] options = additionalOptionsExpanded == null ? null : new QuotedStringTokenizer(additionalOptionsExpanded).toArray();
    for (String composition : compositions) {
        ArgumentListBuilder args = getSCommandArgs(build, listener);
        args.add("cmd=play", "wait", "format=junitxml").add("name=" + composition);
        // if thresholds are included in this post-build action, add them to scommand arguments 
        if (thresholds != null) {
            displayTransactionThreholds(listener.getLogger());
            for (TransactionThreshold threshold : thresholds) {
                args.add("validation=" + threshold.toScommandString());
            }
        }
        String fileName = composition + ".xml";
        // will typically be the full CloudTest folder path).
        if (fileName.startsWith("/")) {
            fileName = fileName.substring(1);
        }
        // Put the file in the test results directory.
        fileName = resultsDir + File.separator + fileName;
        FilePath xml = new FilePath(build.getWorkspace(), fileName);
        // Make sure the directory exists.
        xml.getParent().mkdirs();
        // Add the additional options to the composition if there are any.
        if (options != null) {
            args.add(options);
        }
        if (generatePlotCSV) {
            args.add("outputthresholdcsvdir=" + build.getWorkspace());
        }
        // Run it!
        int exitCode = launcher.launch().cmds(args).pwd(build.getWorkspace()).stdout(xml.write()).stderr(listener.getLogger()).join();
        if (xml.length() == 0) {
            // This should never happen, but just in case...
            return false;
        }
        if (deleteOldResults) {
            // Run SCommand again to clean up the old results.
            args = getSCommandArgs(build, listener);
            args.add("cmd=delete", "type=result").add("path=" + composition).add("maxage=" + maxDaysOfResults);
            launcher.launch().cmds(args).pwd(build.getWorkspace()).stdout(listener).stderr(listener.getLogger()).join();
        }
    }
    // Now that we've finished running all the compositions, pass
    // the results directory off to the JUnit archiver.
    String resultsPattern = resultsDir + "/**/*.xml";
    JUnitResultArchiver archiver = new JUnitResultArchiver(resultsPattern, true, new DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>>(Saveable.NOOP, Collections.singleton(new JunitResultPublisher(null))));
    return archiver.perform(build, launcher, listener);
}
Example 6
Project: hudson.core-master  File: LegacyProjectTest.java View source code
/**
     * Tests unmarshalls FreeStyleProject configuration and checks whether publishers
     * from Project are configured
     *
     * @throws Exception if any.
     */
@Test
public void testConvertPublishersProperty() throws Exception {
    Project project = (Project) Items.getConfigFile(config).read();
    project.setAllowSave(false);
    project.initProjectProperties();
    Hudson hudson = createMock(Hudson.class);
    String mailerKey = "hudson-tasks-Mailer";
    Descriptor<Publisher> mailerDescriptor = createMock(Mailer.DescriptorImpl.class);
    expect(mailerDescriptor.getJsonSafeClassName()).andReturn(mailerKey);
    expect(hudson.getDescriptorOrDie(Mailer.class)).andReturn(mailerDescriptor);
    String jUnitKey = "hudson-task-JUnitResultArchiver";
    Descriptor<Publisher> junitDescriptor = createMock(JUnitResultArchiver.DescriptorImpl.class);
    expect(junitDescriptor.getJsonSafeClassName()).andReturn(jUnitKey);
    expect(hudson.getDescriptorOrDie(JUnitResultArchiver.class)).andReturn(junitDescriptor);
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    replayAll();
    //Publishers should be null, because of legacy implementation. Version < 2.2.0
    assertNull(project.getProperty(mailerKey));
    assertNull(project.getProperty(jUnitKey));
    project.convertPublishersProperties();
    //Verify publishers
    assertNotNull(project.getProperty(mailerKey).getValue());
    assertNotNull(project.getProperty(jUnitKey).getValue());
    verifyAll();
}
Example 7
Project: matrix-project-plugin-master  File: MatrixBuild.java View source code
private void listUpAggregators(Collection<?> values) {
    for (Object v : values) {
        if (v instanceof MatrixAggregatable) {
            MatrixAggregatable ma = (MatrixAggregatable) v;
            MatrixAggregator a = ma.createAggregator(MatrixBuild.this, launcher, listener);
            if (a != null)
                aggregators.add(a);
        } else if (v instanceof JUnitResultArchiver) {
            // originally assignable to MatrixAggregatable
            aggregators.add(new TestResultAggregator(MatrixBuild.this, launcher, listener));
        }
    }
}
Example 8
Project: Quarantine-master  File: QuarantineCoreTest.java View source code
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));
        }
    }
}
Example 9
Project: build-failure-analyzer-plugin-master  File: BuildFailureScannerHudsonTest.java View source code
/**
     * Test whether failed test cases are successfully matched as failure causes.
     *
     * @throws Exception if not so.
     */
@Test
public void testTestResultInterpretation() throws Exception {
    PluginImpl.getInstance().setTestResultParsingEnabled(true);
    FreeStyleProject project = jenkins.createFreeStyleProject();
    project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG));
    project.getBuildersList().add(new TestBuilder() {

        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            build.getWorkspace().child("junit.xml").copyFrom(this.getClass().getResource("junit.xml"));
            return true;
        }
    });
    project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null));
    Future<FreeStyleBuild> future = project.scheduleBuild2(0, new Cause.UserIdCause());
    FreeStyleBuild build = future.get(10, TimeUnit.SECONDS);
    jenkins.assertBuildStatus(Result.UNSTABLE, build);
    FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class);
    assertNotNull(action);
    List<FoundFailureCause> causeListFromAction = action.getFoundFailureCauses();
    assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size());
    assertEquals(causeListFromAction.get(0).getName(), "AFailingTest");
    assertEquals(causeListFromAction.get(0).getDescription(), "Here are details of the failure...");
    assertEquals(new ArrayList<String>(), causeListFromAction.get(0).getCategories());
    assertEquals(causeListFromAction.get(1).getName(), "AnotherFailingTest");
    assertEquals(causeListFromAction.get(1).getDescription(), "More details");
    assertEquals(new ArrayList<String>(), causeListFromAction.get(1).getCategories());
}
Example 10
Project: email-ext-plugin-master  File: OnlyRegressionsTest.java View source code
@Test
public void testOnlyRegressionsAreShown() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject("onlyRegressions");
    project.getPublishersList().add(new JUnitResultArchiver("target/testreports/*.xml", true, null));
    project.getBuildersList().add(new TestBuilder() {

        @Override
        public boolean perform(AbstractBuild<?, ?> abstractBuild, Launcher launcher, BuildListener buildListener) throws InterruptedException, IOException {
            final URL failedTestReport = Thread.currentThread().getContextClassLoader().getResource("hudson/plugins/emailext/testreports/failed_test.xml");
            FilePath workspace = abstractBuild.getWorkspace();
            FilePath testDir = workspace.child("target").child("testreports");
            testDir.mkdirs();
            FilePath reportFile = testDir.child("failed_test.xml");
            reportFile.copyFrom(failedTestReport);
            return true;
        }
    });
    TaskListener listener = StreamTaskListener.fromStdout();
    project.scheduleBuild2(0).get();
    FailedTestsContent failedTestsContent = new FailedTestsContent();
    failedTestsContent.onlyRegressions = true;
    String content = failedTestsContent.evaluate(project.getLastBuild(), listener, FailedTestsContent.MACRO_NAME);
    assertTrue("The failing test should be reported the first time it fails", content.contains("hudson.plugins.emailext"));
    project.scheduleBuild2(0).get();
    content = failedTestsContent.evaluate(project.getLastBuild(), listener, FailedTestsContent.MACRO_NAME);
    assertFalse("The failing test should not be reported the second time it fails", content.contains("hudson.plugins.emailext"));
    assertTrue("The content should state that there are other failing tests still", content.contains("and 1 other failed test"));
}
Example 11
Project: hudson-2.x-master  File: LegacyProjectTest.java View source code
/**
     * Tests unmarshalls FreeStyleProject configuration and checks whether publishers
     * from Project are configured
     *
     * @throws Exception if any.
     */
@Test
public void testConvertPublishersProperty() throws Exception {
    Project project = (Project) Items.getConfigFile(config).read();
    project.setAllowSave(false);
    project.initProjectProperties();
    Hudson hudson = createMock(Hudson.class);
    String mailerKey = "hudson-tasks-Mailer";
    Descriptor<Publisher> mailerDescriptor = createMock(Mailer.DescriptorImpl.class);
    expect(mailerDescriptor.getJsonSafeClassName()).andReturn(mailerKey);
    expect(hudson.getDescriptorOrDie(Mailer.class)).andReturn(mailerDescriptor);
    String jUnitKey = "hudson-task-JUnitResultArchiver";
    Descriptor<Publisher> junitDescriptor = createMock(JUnitResultArchiver.DescriptorImpl.class);
    expect(junitDescriptor.getJsonSafeClassName()).andReturn(jUnitKey);
    expect(hudson.getDescriptorOrDie(JUnitResultArchiver.class)).andReturn(junitDescriptor);
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    replayAll();
    //Publishers should be null, because of legacy implementation. Version < 2.2.0
    assertNull(project.getProperty(mailerKey));
    assertNull(project.getProperty(jUnitKey));
    project.convertPublishersProperties();
    //Verify publishers
    assertNotNull(project.getProperty(mailerKey).getValue());
    assertNotNull(project.getProperty(jUnitKey).getValue());
    verifyAll();
}
Example 12
Project: xunit-plugin-master  File: XUnitPublisher.java View source code
@SuppressWarnings("deprecation")
@Override
public Action getProjectAction(AbstractProject<?, ?> project) {
    JUnitResultArchiver jUnitResultArchiver = project.getPublishersList().get(JUnitResultArchiver.class);
    if (jUnitResultArchiver == null) {
        return new TestResultProjectAction(project);
    }
    return null;
}
Example 13
Project: phabricator-jenkins-plugin-master  File: TestUtils.java View source code
public static Publisher getDefaultXUnitPublisher() {
    return new JUnitResultArchiver(JUNIT_XML);
}