/** * Returns the AWS Device Farm test result for the given id. The id will likely be the default * value generated by Jenkins, which is usually just the human readable name. Return this * test result the ID's match, otherwise scan our previous runs looking for a matching result. * If no match is found, return null. * * @param id * @return */ public TestResult findCorrespondingResult(String id) { if (id == null || getId().equalsIgnoreCase(id)) { return this; } ArrayList<AWSDeviceFarmTestResultAction> prevActions = AWSDeviceFarmUtils.previousAWSDeviceFarmBuilds(build.getProject()); if (prevActions == null || prevActions.isEmpty()) { return null; } for (AWSDeviceFarmTestResultAction action : prevActions) { AWSDeviceFarmTestResult prevResult = action.getResult(); if (prevResult == null) { continue; } if (prevResult.getId().equalsIgnoreCase(id)) { return prevResult; } } return null; }
@Override public hudson.tasks.test.TestResult findCorrespondingResult(String id) { String myID = safe(getName()); String caseName = id; int base = id.indexOf(myID); if (base > 0) { int caseNameStart = base + myID.length() + 1; if (id.length() > caseNameStart) { caseName = id.substring(caseNameStart); } } FlakyCaseResult child = getCaseResult(caseName); if (child != null) { return child; } return null; }
/** * Returns the AppThwack test result for the given id. The id will likely be the default * value generated by Jenkins, which is usually just the human readable name. Return this * test result the ID's match, otherwise scan our previous runs looking for a matching result. * If no match is found, return null. * @param id * @return */ public TestResult findCorrespondingResult(String id) { if (id == null || getId().equalsIgnoreCase(id)) { return this; } ArrayList<AppThwackTestResultAction> prevActions = AppThwackUtils.previousAppThwackBuilds(build.getProject()); if (prevActions == null || prevActions.isEmpty()) { return null; } for (AppThwackTestResultAction action : prevActions) { AppThwackTestResult prevResult = action.getResult(); if (prevResult == null) { continue; } if (prevResult.getId().equalsIgnoreCase(id)) { return prevResult; } } return null; }
public MessageBuilder appendTestSummary(boolean includeFailedTests) { AbstractTestResultAction<?> action = this.build .getAction(AbstractTestResultAction.class); if (action != null) { int total = action.getTotalCount(); int failed = action.getFailCount(); int skipped = action.getSkipCount(); message.append("\n"); message.append("<b>Test Status:</b>\n"); message.append("Passed: " + (total - failed - skipped)); message.append(", Failed: " + failed); message.append(", Skipped: " + skipped); if(includeFailedTests && failed > 0){ message.append("\n<b>Failed Tests:</b>\n"); List<? extends TestResult> failedTests = action.getFailedTests(); for(int i = 0; i<failedTests.size();i++){ TestResult result = failedTests.get(i); String testName = result.getName(); if(testName.length() > 60) { String[] splittedTestName = testName.split("\\."); testName = ""; for(int j = splittedTestName.length - 1;j>=0;j--){ if(testName.length() + splittedTestName[j].length() + 1 > 60) break; testName = splittedTestName[j] + "." + testName; } testName = testName.substring(0,testName.length()-1); } message.append(escape(testName + "\n")); } } } else { message.append("\nNo Tests found."); } return this; }
@Override public String evaluate(AbstractBuild<?, ?> build, TaskListener listener, String macroName) throws MacroEvaluationException, IOException, InterruptedException { AbstractTestResultAction<?> testResultContainer = build.getAction(AbstractTestResultAction.class); StringBuilder testResult = new StringBuilder(); if (testResultContainer != null) { String testResultDescription = testResultContainer.getBuildHealth().getDescription(); testResult.append(testResultDescription); Integer failedUnitTests = testResultContainer.getFailedTests().size(); if (failedUnitTests > 0) { testResult.append("\nFailures:"); Integer processedUnitTests = 0; for (TestResult testResultItem : testResultContainer.getFailedTests()) { testResult.append(Constants.LINE_SEPARATOR).append("\n").append(testResultItem.getFullName()); if ((null != testResultItem.getErrorDetails()) && !testResultItem.getErrorDetails().trim().isEmpty()) { testResult.append("\n-------- Message --------\n").append(testResultItem.getErrorDetails().trim()); } if ((null != testResultItem.getStderr()) && !testResultItem.getStderr().trim().isEmpty()) { testResult.append("\n-------- Stacktrace --------\n").append(testResultItem.getStderr().trim()); } processedUnitTests++; if (processedUnitTests.equals(failedUnitTests)) { testResult.append(Constants.LINE_SEPARATOR); } } } } return testResult.toString(); }
/** * Case results have no children * @return null */ @Override public TestResult findCorrespondingResult(String id) { if (id.equals(safe(getName()))) { return this; } return null; }
@Override public TestResult findCorrespondingResult(String id) { String myID = safe(getName()); int base = id.indexOf(myID); String className = id; // fall back value if (base > 0) { int classNameStart = base + myID.length() + 1; if (classNameStart<id.length()) className = id.substring(classNameStart); } String subId = null; int classNameEnd = className.indexOf('/'); if (classNameEnd > 0) { subId = className.substring(classNameEnd + 1); if (subId.length() == 0) { subId = null; } className = className.substring(0, classNameEnd); } FlakyClassResult child = getClassResult(className); if (child != null && subId != null) return child.findCorrespondingResult(subId); return child; }
/** * Gets the "children" of this test result that passed without a flake * * @return the children of this test result, if any, or an empty collection */ @Override public Collection<? extends hudson.tasks.test.TestResult> getPassedTests() { List<FlakyCaseResult> r = new ArrayList<FlakyCaseResult>(); for (FlakyClassResult clr : classes.values()) { for (FlakyCaseResult cr : clr.getChildren()) { if (cr.isPassed() && !cr.isFlaked()) { r.add(cr); } } } return r; }
/** * Gets the "children" of this test result that were skipped * * @return the children of this test result, if any, or an empty list */ @Override public Collection<? extends TestResult> getSkippedTests() { List<FlakyCaseResult> r = new ArrayList<FlakyCaseResult>(); for (FlakyClassResult clr : classes.values()) { for (FlakyCaseResult cr : clr.getChildren()) { if (cr.isSkipped()) { r.add(cr); } } } return r; }
@Override public FlakyClassResult getPreviousResult() { if (parent == null) { return null; } TestResult pr = parent.getPreviousResult(); if (pr == null) { return null; } if (pr instanceof FlakyPackageResult) { return ((FlakyPackageResult) pr).getClassResult(getName()); } return null; }
public void testFindCorrespondingResult() { FlakyClassResult flakyClassResult = new FlakyClassResult(null, "com.example.ExampleTest"); FlakyCaseResult flakyCaseResult = new FlakyCaseResult(null, "testCase", null); flakyClassResult.add(flakyCaseResult); TestResult result = flakyClassResult .findCorrespondingResult("extraprefix.com.example.ExampleTest.testCase"); assertEquals(flakyCaseResult, result); }
private TestObject mockTestObject(String testName, boolean pass, String url) { TestObject testObject = mock(TestResult.class, testName); when(testObject.getFailCount()).thenReturn(pass ? 0 : 100); when(testObject.getName()).thenReturn(testName); when(testObject.getUrl()).thenReturn(url); return testObject; }
public int getNumberOfSuccessivePasses(CaseResult test) { int count = 0; for (TestResult result : test.getHistory().getList()) { if (result.isPassed()) { count++; } else { return count; } } return count; }
@Override public TestResult findCorrespondingResult(String id) { if (getId().equals(id) || (id == null)) return this; return null; }
private Collection<? extends TestResult> singletonListOfThisOrEmptyList(boolean f) { if (f) return singletonList(this); else return emptyList(); }
public void testFindCorrespondingResultWhereFlakyClassResultNameIsNotSubstring() { FlakyClassResult FlakyClassResult = new FlakyClassResult(null, "aaaa"); FlakyCaseResult FlakyCaseResult = new FlakyCaseResult(null, "tc_bbbb", null); FlakyClassResult.add(FlakyCaseResult); TestResult result = FlakyClassResult.findCorrespondingResult("tc_bbbb"); assertEquals(FlakyCaseResult, result); }
public void testFindCorrespondingResultWhereFlakyClassResultNameIsLastInFlakyCaseResultName() { FlakyClassResult FlakyClassResult = new FlakyClassResult(null, "aaaa"); FlakyCaseResult FlakyCaseResult = new FlakyCaseResult(null, "tc_aaaa", null); FlakyClassResult.add(FlakyCaseResult); TestResult result = FlakyClassResult.findCorrespondingResult("tc_aaaa"); assertEquals(FlakyCaseResult, result); }
/** * Gets the "children" of this test result that failed * * @return the children of this test result, if any, or an empty collection */ @Override public Collection<? extends TestResult> getFailedTests() { return singletonListOfThisOrEmptyList(isFailed()); }
/** * 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 TestResult> getPassedTests() { return singletonListOfThisOrEmptyList(isPassed()); }
/** * Gets the "children" of this test result that were skipped * * @return the children of this test result, if any, or an empty list */ @Override public Collection<? extends TestResult> getSkippedTests() { return singletonListOfThisOrEmptyList(isSkipped()); }