hudson.tasks.test.TestResult Java Examples

The following examples show how to use hudson.tasks.test.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: AWSDeviceFarmTestResult.java    From aws-device-farm-jenkins-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 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 test result ID
 * @return the AWS Device Farm test result for the given id
 */
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;
}
 
Example #2
Source File: ClassResult.java    From junit-plugin with MIT License 6 votes vote down vote up
@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);
         }
     } 
     CaseResult child = getCaseResult(caseName);
     if (child != null) {
         return child;
     }
     return null;
 }
 
Example #3
Source File: FlakyClassResult.java    From flaky-test-handler-plugin with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #4
Source File: CaseResult.java    From junit-plugin with MIT License 6 votes vote down vote up
@Override
public Run<?,?> getRun() {
    SuiteResult sr = getSuiteResult();
    if (sr==null) {
        LOGGER.warning("In getOwner(), getSuiteResult is null");
        return null;
    }

    hudson.tasks.junit.TestResult tr = sr.getParent();

    if (tr == null) {
        LOGGER.warning("In getOwner(), suiteResult.getParent() is null.");
        return null;
    }

    return tr.getRun();
}
 
Example #5
Source File: JUnitParserTest.java    From junit-plugin with MIT License 6 votes vote down vote up
@Override
public boolean perform(AbstractBuild<?, ?> build,
                       Launcher launcher, BuildListener listener)
        throws InterruptedException, IOException {
    System.out.println("in perform...");

    // First touch all the files, so they will be recently modified
    for (FilePath f : build.getWorkspace().list()) {
        f.touch(System.currentTimeMillis());
    }

    System.out.println("...touched everything");
    hudson.tasks.junit.TestResult result = (new JUnitParser()).parseResult(testResultLocation, build,
            null, build.getWorkspace(), launcher, listener);

    System.out.println("back from parse");
    assertNotNull("we should have a non-null result", result);
    assertTrue("result should be a TestResult", result instanceof hudson.tasks.junit.TestResult);
    System.out.println("We passed some assertions in the JUnitParserTestBuilder");
    theResult = result;
    return result != null;
}
 
Example #6
Source File: History.java    From junit-plugin with MIT License 6 votes vote down vote up
/**
 * Graph of # of tests over time.
 *
 * @return a graph of number of tests over time.
 */
public Graph getCountGraph() {
    return new GraphImpl("") {
        protected DataSetBuilder<String, ChartLabel> createDataSet() {
            DataSetBuilder<String, ChartLabel> data = new DataSetBuilder<String, ChartLabel>();

            List<TestResult> list;
            try {
            	list = getList(
            			Integer.parseInt(Stapler.getCurrentRequest().getParameter("start")), 
            			Integer.parseInt(Stapler.getCurrentRequest().getParameter("end")));
            } catch (NumberFormatException e) {
            	list = getList();
            }
            
            for (TestResult o: list) {
                data.add(o.getPassCount(), "2Passed", new ChartLabel(o));
                data.add(o.getFailCount(), "1Failed", new ChartLabel(o));
                data.add(o.getSkipCount(), "0Skipped", new ChartLabel(o));
            }
            return data;
        }
    };
}
 
Example #7
Source File: ClassResult.java    From junit-plugin with MIT License 5 votes vote down vote up
@Override
public ClassResult getPreviousResult() {
    if(parent==null)   return null;
    TestResult pr = parent.getPreviousResult();
    if(pr==null)    return null;
    if(pr instanceof PackageResult) {
        return ((PackageResult)pr).getClassResult(getName());
}
    return null;
}
 
Example #8
Source File: FlakyClassResultTest.java    From flaky-test-handler-plugin with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #9
Source File: FlakyClassResult.java    From flaky-test-handler-plugin with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #10
Source File: FlakyPackageResult.java    From flaky-test-handler-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: FlakyPackageResult.java    From flaky-test-handler-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: FlakyPackageResult.java    From flaky-test-handler-plugin with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #13
Source File: FlakyCaseResult.java    From flaky-test-handler-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Case results have no children
 * @return null
 */
@Override
public TestResult findCorrespondingResult(String id) {
  if (id.equals(safe(getName()))) {
    return this;
  }
  return null;
}
 
Example #14
Source File: ClassResultTest.java    From junit-plugin with MIT License 5 votes vote down vote up
@Test
public void testFindCorrespondingResultWhereClassResultNameIsLastInCaseResultName() {
	ClassResult classResult = new ClassResult(null, "aaaa");

	CaseResult caseResult = new CaseResult(null, "tc_aaaa", null);

	classResult.add(caseResult);

	TestResult result = classResult.findCorrespondingResult("tc_aaaa");
	assertEquals(caseResult, result);
}
 
Example #15
Source File: ClassResultTest.java    From junit-plugin with MIT License 5 votes vote down vote up
@Test
public void testFindCorrespondingResultWhereClassResultNameIsNotSubstring() {
	ClassResult classResult = new ClassResult(null, "aaaa");

	CaseResult caseResult = new CaseResult(null, "tc_bbbb", null);

	classResult.add(caseResult);

	TestResult result = classResult.findCorrespondingResult("tc_bbbb");
	assertEquals(caseResult, result);
}
 
Example #16
Source File: ClassResultTest.java    From junit-plugin with MIT License 5 votes vote down vote up
@Test
public void testFindCorrespondingResult() {
	ClassResult classResult = new ClassResult(null, "com.example.ExampleTest");

	CaseResult caseResult = new CaseResult(null, "testCase", null);

	classResult.add(caseResult);

	TestResult result = classResult.findCorrespondingResult("extraprefix.com.example.ExampleTest.testCase");
	assertEquals(caseResult, result);
}
 
Example #17
Source File: History.java    From junit-plugin with MIT License 5 votes vote down vote up
/**
  * Graph of duration of tests over time.
  *
  * @return a graph of duration of tests over time.
  */
 public Graph getDurationGraph() {
    return new GraphImpl("seconds") {
 	   
        protected DataSetBuilder<String, ChartLabel> createDataSet() {
            DataSetBuilder<String, ChartLabel> data = new DataSetBuilder<String, ChartLabel>();
            
            List<TestResult> list;
            try {
            	list = getList(
            			Integer.parseInt(Stapler.getCurrentRequest().getParameter("start")), 
            			Integer.parseInt(Stapler.getCurrentRequest().getParameter("end")));
            } catch (NumberFormatException e) {
            	list = getList();
            }
            
for (hudson.tasks.test.TestResult o: list) {
                data.add(((double) o.getDuration()), "", new ChartLabel(o)  {
                    @Override
                    public Color getColor() {
                        if (o.getFailCount() > 0)
                            return ColorPalette.RED;
                        else if (o.getSkipCount() > 0)
                            return ColorPalette.YELLOW;
                        else
                            return ColorPalette.BLUE;
                    }
                });
            }
            return data;
        }
        
    };
 }
 
Example #18
Source File: History.java    From junit-plugin with MIT License 5 votes vote down vote up
public List<TestResult> getList(int start, int end) {
	List<TestResult> list = new ArrayList<TestResult>();
	end = Math.min(end, testObject.getRun().getParent().getBuilds().size());
	for (Run<?,?> b: testObject.getRun().getParent().getBuilds().subList(start, end)) {
		if (b.isBuilding()) continue;
		TestResult o = testObject.getResultInRun(b);
		if (o != null) {
			list.add(o);
		}
	}
	return list;
}
 
Example #19
Source File: PackageResult.java    From junit-plugin with MIT License 5 votes vote down vote up
@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);
    }

    ClassResult child = getClassResult(className);
    if (child != null && subId != null)
        return child.findCorrespondingResult(subId);

    return child;
}
 
Example #20
Source File: CaseResult.java    From junit-plugin with MIT License 5 votes vote down vote up
/**
 * Case results have no children
 * @return null
 */
@Override
public TestResult findCorrespondingResult(String id) {
    if (id.equals(safe(getName()))) {
        return this;
}
    return null;
}
 
Example #21
Source File: JUnitParserTest.java    From junit-plugin with MIT License 4 votes vote down vote up
@LocalData
@Test
public void testJustParsing() throws Exception {
    FreeStyleBuild build = project.scheduleBuild2(0).get(100, TimeUnit.MINUTES);
    assertNotNull(build);
    
    // Now let's examine the result. We know lots of stuff about it because
    // we've analyzed the xml source files by hand.
    assertNotNull("we should have a result in the static member", theResult);

    // Check the overall counts. We should have 1 failure, 0 skips, and 132 passes.
    Collection<? extends TestResult> children = theResult.getChildren();
    assertFalse("Should have several packages", children.isEmpty());
    assertTrue("Should have several pacakges", children.size() > 3); 
    int passCount = theResult.getPassCount();
    assertEquals("expecting many passes", 131, passCount);
    int failCount = theResult.getFailCount();
    assertEquals("we should have one failure", 1, failCount);
    assertEquals("expected 0 skips", 0, theResult.getSkipCount());
    assertEquals("expected 132 total tests", 132, theResult.getTotalCount()); 

    // Dig in to the failed test 
    final String EXPECTED_FAILING_TEST_NAME = "testDataCompatibilityWith1_282";
    final String EXPECTED_FAILING_TEST_CLASSNAME = "hudson.security.HudsonPrivateSecurityRealmTest";

    Collection<? extends TestResult> failingTests = theResult.getFailedTests();
    assertEquals("should have one failed test", 1, failingTests.size());
    Map<String, TestResult> failedTestsByName = new HashMap<String, TestResult>();
    for (TestResult r: failingTests) {
        failedTestsByName.put(r.getName(), r);  
    }
    assertTrue("we've got the expected failed test", failedTestsByName.containsKey(EXPECTED_FAILING_TEST_NAME));
    TestResult firstFailedTest = failedTestsByName.get(EXPECTED_FAILING_TEST_NAME);
    assertFalse("should not have passed this test", firstFailedTest.isPassed());
    
    assertTrue(firstFailedTest instanceof CaseResult);
    CaseResult firstFailedTestJunit = (CaseResult)firstFailedTest;
    assertEquals(EXPECTED_FAILING_TEST_CLASSNAME, firstFailedTestJunit.getClassName());

    // TODO: Dig in to the passed tests, too



}
 
Example #22
Source File: History.java    From junit-plugin with MIT License 4 votes vote down vote up
public List<TestResult> getList() {
	return getList(0, testObject.getRun().getParent().getBuilds().size());
}
 
Example #23
Source File: CaseResult.java    From junit-plugin with MIT License 4 votes vote down vote up
private Collection<? extends hudson.tasks.test.TestResult> singletonListOfThisOrEmptyList(boolean f) {
    if (f)
        return singletonList(this);
    else
        return emptyList();
}
 
Example #24
Source File: History.java    From junit-plugin with MIT License 4 votes vote down vote up
public ChartLabel(TestResult o) {
    this.o = o;
    this.url = null;
}
 
Example #25
Source File: PackageResult.java    From junit-plugin with MIT License 4 votes vote down vote up
PackageResult(hudson.tasks.junit.TestResult parent, String packageName) {
    this.packageName = packageName;
    this.parent = parent;
}
 
Example #26
Source File: PackageResult.java    From junit-plugin with MIT License 4 votes vote down vote up
public hudson.tasks.junit.TestResult getParent() {
	return parent;
}
 
Example #27
Source File: FlakyCaseResult.java    From flaky-test-handler-plugin with Apache License 2.0 4 votes vote down vote up
private Collection<? extends TestResult> singletonListOfThisOrEmptyList(boolean f) {
  if (f)
    return singletonList(this);
  else
    return emptyList();
}
 
Example #28
Source File: FlakyClassResultTest.java    From flaky-test-handler-plugin with Apache License 2.0 3 votes vote down vote up
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);
}
 
Example #29
Source File: FlakyClassResultTest.java    From flaky-test-handler-plugin with Apache License 2.0 3 votes vote down vote up
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);
}
 
Example #30
Source File: CaseResult.java    From junit-plugin with MIT License 2 votes vote down vote up
/**
 * 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());
}