@Test public void testNotOkTestResult() { assertNotNull(notOkTestResult); assertTrue(notOkTestResult.getTestNumber() > 0); assertEquals(notOkTestResult.getStatus(), StatusValues.NOT_OK); assertNull(notOkTestResult.getDirective()); }
@Override public hudson.tasks.test.TestResult findCorrespondingResult(String id) { String groupName; String remainingId = null; int groupNameEnd = id.indexOf('/'); if (groupNameEnd < 0) { groupName = id; remainingId = null; } else { groupName = id.substring(0, groupNameEnd); if (groupNameEnd != id.length()) { remainingId = id.substring(groupNameEnd + 1); if (remainingId.length() == 0) { remainingId = null; } } } TestResult group = getGroupBySuiteName(groupName); if (group != null) { if (remainingId != null) { return group.findCorrespondingResult(remainingId); } else { return group; } } return null; }
public TestRun(TestResult testResult) { this.testIdentifikator = testResult.getTest().getIdentifikator(); this.site = testResult.getSite().getName(); this.timeRun = new Date(); this.resultEnum = testResult.getResultEnum(); this.message = testResult.getMessage(); }
/** * Summarize the last test results from the passed set of jobs, including the packages of the job. * If a job doesn't include any tests, add a 0 summary. * * @param jobs * @return */ public static TestResultSummary getDetailedTestResultSummary(Collection<TopLevelItem> jobs) { TestResultSummary summary = new TestResultSummary(); for (TopLevelItem item : jobs) { if (item instanceof Job) { Job job = (Job) item; // create summary for the last run Run run = job.getLastBuild(); if (run != null) { TestResult testResult = TestUtil.getTestResult(job.getLastBuild()); summary.addTestResult(testResult); AbstractTestResultAction tra = run.getAction(AbstractTestResultAction.class); if (tra != null) { if (tra.getResult() instanceof MetaTabulatedResult) { MetaTabulatedResult result = (MetaTabulatedResult) tra.getResult(); // add test results for the packages for (hudson.tasks.test.TestResult child : result.getChildren()) { PackageResult sub = new PackageResult( child, child.getTotalCount(), child.getFailCount(), child.getSkipCount()); testResult.getPackageResults().add(sub); } } } } } } return summary; }
@Override public void onTestStart(ITestResult tr) { super.onTestStart(tr); logger.info(tr.getName() + " Start"); testResult.setDate(ts.getDate("-")); testResult.setStartTime(ts.getTime(":")); }
private void playersTest(TestResult result) { Players players = new Players(); players.Add(new Player("P1", Color.GREEN)); players.Add(new Player("P2", Color.RED)); players.Add(new Player("P3", Color.BLUE)); players.Add(new Player("P4", Color.YELLOW)); if (players.setup(126)) { for (int i = 0; i < players.players.length; i++) { if (players.players[i].getShips().length != 9) { result.addComment(players.players[i].getName() + ": " + players.players[i].getShips()); result.setResult(false); } } int indexsum = 0; int indexprevsum = 0; for (int i = 0; i < players.players.length; i++) { indexsum = 0; for (int j = 0; j < players.players[i].getShips().length; j++) { indexsum += players.players[i].getShips()[j].getIndex(); } } } else result.setResult(false); }
private Iterable<TestResult> pruneToDepth(List<TestResult> results, Integer depth) { // Prune the response to the requested depth // 0 - TestResult // 1 - TestCapability // 2 - TestSuite // 3 - TestCase // 4 - Entire response // null - Entire response if (depth == null || depth > 3) { return results; } for (TestResult result : results) { if (depth == 0) { result.getTestCapabilities().clear(); } else { for (TestCapability testCapability : result.getTestCapabilities()) { if (depth == 1) { testCapability.getTestSuites().clear(); } else { for (TestSuite testSuite : testCapability.getTestSuites()) { if (depth == 2) { testSuite.getTestCases().clear(); } else { // depth == 3 for (TestCase testCase : testSuite.getTestCases()) { testCase.getTestSteps().clear(); } } } } } } } return results; }
@Override public String create(TestDataCreateRequest request) throws HygieiaException { /** * Step 1: create Collector if not there Step 2: create Collector item if not there Step 3: * Insert test data if new. If existing, update it */ Collector collector = createCollector(); if (collector == null) { throw new HygieiaException( "Failed creating Test collector.", HygieiaException.COLLECTOR_CREATE_ERROR); } CollectorItem collectorItem = createCollectorItem(collector, request); if (collectorItem == null) { throw new HygieiaException( "Failed creating Test collector item.", HygieiaException.COLLECTOR_ITEM_CREATE_ERROR); } TestResult testResult = createTest(collectorItem, request); if (testResult == null) { throw new HygieiaException( "Failed inserting/updating Test information.", HygieiaException.ERROR_INSERTING_DATA); } return testResult.getId().toString(); }
public void testNoArgTestCasePasses() { Test t = new TestSuite(NoArgTestCaseTest.class); TestResult result = new TestResult(); t.run(result); assertTrue(result.runCount() == 1); assertTrue(result.failureCount() == 0); assertTrue(result.errorCount() == 0); }
@Test public void testCommentText() { assertEquals( okTestResultSkip.getComments().get(0).getText(), "This status is set to true in another method."); okTestResult.setComments(Collections.<Comment>emptyList()); assertTrue(okTestResult.getComments().size() == 0); }
public void testActiveRepeatedTest1() { Test test = new RepeatedTest(createActiveTestSuite(), 1); TestResult result = new TestResult(); test.run(result); assertEquals(100, result.runCount()); assertEquals(0, result.failureCount()); assertEquals(0, result.errorCount()); }
@Test public void testOkTestResultSkip() { assertNotNull(okTestResultSkip); assertTrue(okTestResultSkip.getTestNumber() > 0); okTestResultSkip.setStatus(StatusValues.OK); assertEquals(okTestResultSkip.getStatus(), StatusValues.OK); assertNotNull(okTestResultSkip.getDirective()); }
@Override public void perform(Run build, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException { listener.getLogger().println(Messages.JUnitResultArchiver_Recording()); final String testResults = build.getEnvironment(listener).expand(this.testResults); TestResult result = parse(testResults, build, workspace, launcher, listener); synchronized (build) { // TODO can the build argument be omitted now, or is it used prior to the call to addAction? TestResultAction action = build.getAction(TestResultAction.class); boolean appending; if (action == null) { appending = false; action = new TestResultAction(build, result, listener); } else { appending = true; result.freeze(action); action.mergeResult(result, listener); } action.setHealthScaleFactor(getHealthScaleFactor()); // overwrites previous value if appending if (result.isEmpty()) { if (build.getResult() == Result.FAILURE) { // most likely a build failed before it gets to the test phase. // don't report confusing error message. return; } if (this.allowEmptyResults) { // User allow empty results listener.getLogger().println(Messages.JUnitResultArchiver_ResultIsEmpty()); return; } // most likely a configuration error in the job - e.g. false pattern to match the JUnit // result files throw new AbortException(Messages.JUnitResultArchiver_ResultIsEmpty()); } // TODO: Move into JUnitParser [BUG 3123310] List<Data> data = action.getData(); if (testDataPublishers != null) { for (TestDataPublisher tdp : testDataPublishers) { Data d = tdp.contributeTestData(build, workspace, launcher, listener, result); if (d != null) { data.add(d); } } } if (appending) { build.save(); } else { build.addAction(action); } if (action.getResult().getFailCount() > 0) build.setResult(Result.UNSTABLE); } }
@Override public void testAssertionVerified(Assertion assertion, TestResult testResult) { if (testResult != null && testResult.doesCount() && (testResult.getExecutionResult() == ExecutionResult.FAIL || testResult.getExecutionResult() == ExecutionResult.ERROR)) { firstFailure(testResult.getExecutionResult(), createMessage(testResult)); } }
@Test public void commandsAreNotRunForInvalidTests() throws Exception { commandList.add(command1); when(parsedTestUnit.getError()).thenReturn(Optional.of("Invalid Command on line 3")); TestResult testResult = singleTestRunner.runTest(lineBuffer, lineWriter, parsedTestUnit); assertEquals(TestResult.INVALID, testResult.getStatus()); verify(commandRunner, never()).runCommand(command1, lineBuffer, lineWriter); }
@Test public void testExceptionedCommandYieldsExceptionedTest() throws Exception { commandList.add(command1); when(commandRunner.runCommand(command1, lineBuffer, lineWriter)).thenReturn(commandResult1); when(commandResult1.getStatus()).thenReturn(CommandResult.EXCEPTION); TestResult testResult = singleTestRunner.runTest(lineBuffer, lineWriter, parsedTestUnit); assertEquals(TestResult.EXCEPTION, testResult.getStatus()); }
private void addErrorMessage(TestResult testResult, String message) { String processedTestsMessage = myRunTests <= 0 ? "None of tests was run" : myRunTests + " tests processed"; try { testResult.startTest(this); testResult.addError(this, new Throwable(processedTestsMessage + " before: " + message)); testResult.endTest(this); } catch (Exception e) { e.printStackTrace(); } }
public void setParentAction(SuiteGroupResultAction parentAction) { if (this.parentAction == parentAction) { return; } this.parentAction = parentAction; // Tell all of our children about the parent action, too. for (TestResult group : childrenBySuiteName.values()) { group.setParentAction(parentAction); } }
static void runTest(File jarFile, String expectedErrorMessage) { TestResult tr = doExec(TestHelper.javaCmd, "-jar", jarFile.getAbsolutePath()); if (isEnglishLocale() && !tr.contains(expectedErrorMessage)) { System.out.println(tr); throw new RuntimeException("expected string not found"); } if (tr.isOK()) { System.out.println(tr); throw new RuntimeException("test exit with status 0"); } }
public static void main(String argv[]) { TestResult result = new TestResult(); TestCase testA = new TestSql("testMetaData"); TestCase testB = new TestSql("testDoubleNaN"); TestCase testC = new TestSql("testAny"); testA.run(result); testB.run(result); testC.run(result); System.out.println("TestSql error count: " + result.failureCount()); }
/** Update the recorded test results with new or changed results. Reports any change. */ void update(ITestCaseElement elt) { Test test = new Test(elt); TestResult result = new TestResult(elt, project); if (!results.containsKey(test)) { results.put(test, result); } else if (!result.equals(results.get(test))) { results.put(test, result); } else { return; } reportAdd(test, result); }
public void runNext() throws TestFailException, UnsupportedEncodingException { // Get first file and remove it from list InputOutput current = inputOutput.remove(0); // Create List with only first input in List<String> inputFiles = new ArrayList<String>(); inputFiles.add(null != commonInputFile ? commonInputFile : current.getName() + ".input"); // Excute Main on that input List<String> cmdLine = new ArrayList<String>(); cmdLine.add("--encoding"); cmdLine.add(inputFileEncoding); classExecResult = Exec.execClass( className, testPath.toString(), cmdLine, inputFiles, Main.jflexTestVersion, outputFileEncoding); if (Main.verbose) { System.out.println("Running scanner on [" + current.getName() + "]"); } // check for output conformance File expected = new File(current.getName() + ".output"); if (expected.exists()) { DiffStream check = new DiffStream(); String diff; try { diff = check.diff( jflexDiff, new StringReader(classExecResult.getOutput()), new InputStreamReader(new FileInputStream(expected), outputFileEncoding)); } catch (FileNotFoundException e) { System.out.println("Error opening file " + expected); throw new TestFailException(); } catch (UnsupportedEncodingException e) { System.out.println("Unsupported encoding '" + outputFileEncoding + "'"); throw new TestFailException(); } if (diff != null) { System.out.println("Test failed, unexpected output: " + diff); System.out.println("Test output: " + classExecResult.getOutput()); throw new TestFailException(); } } else { System.out.println("Warning: no file for expected output [" + expected + "]"); } // System.out.println(classExecResult); }
@Test public void testSuccessThenFailureYieldsFailedTest() throws Exception { commandList.add(command1); commandList.add(command2); when(commandRunner.runCommand(command1, lineBuffer, lineWriter)).thenReturn(commandResult1); when(commandRunner.runCommand(command2, lineBuffer, lineWriter)).thenReturn(commandResult2); when(commandResult1.getStatus()).thenReturn(CommandResult.SUCCESS); when(commandResult2.getStatus()).thenReturn(CommandResult.FAILURE); TestResult testResult = singleTestRunner.runTest(lineBuffer, lineWriter, parsedTestUnit); assertEquals(TestResult.FAILURE, testResult.getStatus()); }
@Test public void testCommandsAreNotRunAfterException() throws Exception { commandList.add(command1); commandList.add(command2); when(commandRunner.runCommand(command1, lineBuffer, lineWriter)).thenReturn(commandResult1); when(commandResult1.getStatus()).thenReturn(CommandResult.EXCEPTION); when(commandResult2.getStatus()).thenReturn(CommandResult.SUCCESS); TestResult testResult = singleTestRunner.runTest(lineBuffer, lineWriter, parsedTestUnit); assertEquals(TestResult.EXCEPTION, testResult.getStatus()); verify(commandRunner, never()).runCommand(command2, lineBuffer, lineWriter); }
private void assertTestResults(FreeStyleBuild build) { TestResultAction testResultAction = build.getAction(TestResultAction.class); assertNotNull("no TestResultAction", testResultAction); TestResult result = testResultAction.getResult(); assertNotNull("no TestResult", result); assertEquals("should have 1 failing test", 1, testResultAction.getFailCount()); assertEquals("should have 1 failing test", 1, result.getFailCount()); assertEquals("should have 132 total tests", 132, testResultAction.getTotalCount()); assertEquals("should have 132 total tests", 132, result.getTotalCount()); }
public static void runTestAndExpect( final Iterable4 tests, int expFailures, boolean checkException) { final TestResult result = new TestResult(); new TestRunner(tests).run(result); if (expFailures != result.failures().size()) { Assert.fail(result.failures().toString()); } if (checkException) { for (Iterator4 iter = result.failures().iterator(); iter.moveNext(); ) { TestFailure failure = (TestFailure) iter.current(); Assert.areEqual(EXCEPTION, failure.reason()); } } }
private void manifestTest(TestResult result) { Fleet fleet = new Fleet(); try { fleet.add("Fast"); fleet.add("Medium"); fleet.add("Slow"); if (!Arrays.toString(fleet.manifest).equals("[Fast, Medium, Slow]")) { result.addComment("Invalid Manifest: " + Arrays.toString(fleet.manifest)); result.setResult(false); } else result.addComment("Manifest add: Passed"); } catch (Exception e) { result.setException(e); } }
public void testExceptionRunningAndTearDown() { // This test documents the current behavior. With 1.4, we should // wrap the exception thrown while running with the exception thrown // while tearing down Test t = new TornDown() { public void tearDown() { throw new Error("tearDown"); } }; TestResult result = new TestResult(); t.run(result); TestFailure failure = (TestFailure) result.errors().nextElement(); assertEquals("tearDown", failure.thrownException().getMessage()); }
@Before public void setUp() { okTestResult = new TestResult(StatusValues.OK, 1); okTestResult.setDescription("- First test"); notOkTestResult = new TestResult(); notOkTestResult.setStatus(StatusValues.NOT_OK); notOkTestResult.setTestNumber(2); okTestResultSkip = new TestResult(StatusValues.NOT_OK, 3); Directive skipDirective = new Directive(DirectiveValues.SKIP, "Skip it until next release of the produce."); okTestResultSkip.setDirective(skipDirective); final Comment comment = new Comment("This status is set to true in another method."); comment.setInline(Boolean.TRUE); okTestResultSkip.addComment(comment); }
private void assertTestRuns(int... failingIndices) { IntByRef counter = new IntByRef(); TestResult result = new TestResult() { @Override public void testStarted(Test test) { super.testStarted(test); Assert.isInstanceOf(CountingTest.class, test); } }; new TestRunner(Iterators.iterable(new SimpleTestSuite(counter, NUM_TESTS, failingIndices))) .run(result); Assert.areEqual(NUM_TESTS, result.testCount()); Assert.areEqual(failingIndices.length, result.failures().size()); Assert.areEqual(NUM_TESTS + 2, counter.value); }