hudson.tasks.junit.TestResult Java Examples
The following examples show how to use
hudson.tasks.junit.TestResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JUnitTestProvider.java From phabricator-jenkins-plugin with MIT License | 6 votes |
/** * 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; }
Example #2
Source File: FlakyTestResultAction.java From flaky-test-handler-plugin with Apache License 2.0 | 6 votes |
/** * Construct a FlakyTestResultAction object with Run and BuildListener * * @param build this build * @param listener listener of this build */ public FlakyTestResultAction(AbstractBuild build, Launcher launcher, TaskListener 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) { VirtualChannel channel = launcher.getChannel(); if(channel == null) { throw new InterruptedException("Could not get channel to run a program remotely."); } FlakyTestResult flakyTestResult = channel.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"); } }
Example #3
Source File: TestResultsTest.java From github-autostatus-plugin with MIT License | 5 votes |
@Test public void testfromJUnitTestResultsNotEmpty() { TestResultAction testResultAction = mock(TestResultAction.class); TestResult testResult = PowerMockito.mock(TestResult.class); SuiteResult suiteResult = PowerMockito.mock(SuiteResult.class); ArrayList<SuiteResult> suiteResults = new ArrayList<>(); suiteResults.add(suiteResult); ArrayList<CaseResult> testCases = new ArrayList<>(); CaseResult caseResult = mock(CaseResult.class); when(caseResult.isPassed()).thenReturn(true); when(caseResult.isFailed()).thenReturn(false); when(caseResult.isSkipped()).thenReturn(false); testCases.add(caseResult); when(suiteResult.getCases()).thenReturn(testCases); when(testResultAction.getResult()).thenReturn(testResult); when(testResult.getSuites()).thenReturn(suiteResults); TestResults instance = TestResults.fromJUnitTestResults(testResultAction); assertNotNull(instance); assertEquals(1, instance.getTestSuites().size()); assertEquals(1, instance.getPassedTestCaseCount()); assertEquals(0, instance.getSkippedTestCaseCount()); assertEquals(0, instance.getFailedTestCaseCount()); }
Example #4
Source File: JUnitTestProvider.java From phabricator-jenkins-plugin with MIT License | 5 votes |
private TestResult getJUnitResults() { Run<?, ?> build = getBuild(); TestResultAction jUnitAction = build.getAction(TestResultAction.class); if (jUnitAction == null) { return null; } return jUnitAction.getResult(); }
Example #5
Source File: JUnitTestProviderTest.java From phabricator-jenkins-plugin with MIT License | 5 votes |
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; }
Example #6
Source File: JUnitResultsStepTest.java From junit-plugin with MIT License | 5 votes |
public static void assertBranchResults(WorkflowRun run, int suiteCount, int testCount, int failCount, String branchName, String stageName, String innerStageName) { FlowExecution execution = run.getExecution(); DepthFirstScanner scanner = new DepthFirstScanner(); BlockStartNode aBranch = (BlockStartNode)scanner.findFirstMatch(execution, branchForName(branchName)); assertNotNull(aBranch); TestResult branchResult = assertBlockResults(run, suiteCount, testCount, failCount, aBranch); String namePrefix = stageName + " / " + branchName; if (innerStageName != null) { namePrefix += " / " + innerStageName; } for (CaseResult c : branchResult.getPassedTests()) { assertEquals(namePrefix + " / " + c.getTransformedTestName(), c.getDisplayName()); } }
Example #7
Source File: JUnitResultsStepTest.java From junit-plugin with MIT License | 5 votes |
private static TestResult assertBlockResults(WorkflowRun run, int suiteCount, int testCount, int failCount, BlockStartNode blockNode) { assertNotNull(blockNode); TestResultAction action = run.getAction(TestResultAction.class); assertNotNull(action); TestResult aResult = action.getResult().getResultForPipelineBlock(blockNode.getId()); assertNotNull(aResult); assertEquals(suiteCount, aResult.getSuites().size()); assertEquals(testCount, aResult.getTotalCount()); assertEquals(failCount, aResult.getFailCount()); if (failCount > 0) { assertThat(findJUnitSteps(blockNode), CoreMatchers.hasItem(hasWarningAction())); } else { assertThat(findJUnitSteps(blockNode), CoreMatchers.not(CoreMatchers.hasItem(hasWarningAction()))); } PipelineBlockWithTests aBlock = action.getResult().getPipelineBlockWithTests(blockNode.getId()); assertNotNull(aBlock); List<String> aTestNodes = new ArrayList<>(aBlock.nodesWithTests()); TestResult aFromNodes = action.getResult().getResultByNodes(aTestNodes); assertNotNull(aFromNodes); assertEquals(aResult.getSuites().size(), aFromNodes.getSuites().size()); assertEquals(aResult.getFailCount(), aFromNodes.getFailCount()); assertEquals(aResult.getSkipCount(), aFromNodes.getSkipCount()); assertEquals(aResult.getPassCount(), aFromNodes.getPassCount()); return aResult; }
Example #8
Source File: JUnitResultsStepTest.java From junit-plugin with MIT License | 5 votes |
private void assertExpectedResults(Run<?,?> run, int suiteCount, int testCount, String... nodeIds) throws Exception { TestResultAction action = run.getAction(TestResultAction.class); assertNotNull(action); TestResult result = action.getResult().getResultByNodes(Arrays.asList(nodeIds)); assertNotNull(result); assertEquals(suiteCount, result.getSuites().size()); assertEquals(testCount, result.getTotalCount()); }
Example #9
Source File: TestResultsTest.java From github-autostatus-plugin with MIT License | 5 votes |
@Test public void testfromJUnitTestResultsEmpty() { TestResultAction testResultAction = mock(TestResultAction.class); when(testResultAction.getResult()).thenReturn(new TestResult()); TestResults instance = TestResults.fromJUnitTestResults(testResultAction); assertNotNull(instance); assertEquals(0, instance.getPassedTestCaseCount()); assertEquals(0, instance.getSkippedTestCaseCount()); assertEquals(0, instance.getFailedTestCaseCount()); }
Example #10
Source File: FlakyTestResultAction.java From flaky-test-handler-plugin with Apache License 2.0 | 5 votes |
/** * 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; }
Example #11
Source File: JUnitFlakyTestDataPublisher.java From flaky-test-handler-plugin with Apache License 2.0 | 5 votes |
@Override public TestResultAction.Data contributeTestData(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener, TestResult testResult) throws IOException, InterruptedException { VirtualChannel channel = launcher.getChannel(); if(channel == null) { throw new InterruptedException("Could not get channel to run a program remotely."); } FlakyTestResult flakyTestResult = channel.call(new FlakyTestResultCollector(testResult)); // TODO consider the possibility that there is >1 such action flakyTestResult.freeze(run.getAction(AbstractTestResultAction.class), run); return new JUnitFlakyTestData(flakyTestResult); }
Example #12
Source File: DeflakeActionIntegrationTest.java From flaky-test-handler-plugin with Apache License 2.0 | 4 votes |
@Override public synchronized void setResult(TestResult result, BuildListener listener) { }
Example #13
Source File: DeflakeActionIntegrationTest.java From flaky-test-handler-plugin with Apache License 2.0 | 4 votes |
public FailingTestResultAction() { super(new TestResult(), new StreamBuildListener(System.out)); }
Example #14
Source File: FlakyTestResult.java From flaky-test-handler-plugin with Apache License 2.0 | 4 votes |
@Override public hudson.tasks.test.TestResult findCorrespondingResult(String id) { return testResultInstance.findCorrespondingResult(id); }
Example #15
Source File: FlakyTestResultCollector.java From flaky-test-handler-plugin with Apache License 2.0 | 4 votes |
public FlakyTestResultCollector(TestResult testResult) { this.testResult = testResult; }
Example #16
Source File: JUnitResultsStepTest.java From junit-plugin with MIT License | 4 votes |
@Override public TestResultAction.Data contributeTestData(Run<?,?> run, FilePath workspace, Launcher launcher, TaskListener listener, TestResult testResult) throws IOException, InterruptedException { return null; }
Example #17
Source File: FlakyTestResult.java From flaky-test-handler-plugin with Apache License 2.0 | 2 votes |
/** * 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; }