Java Code Examples for org.junit.runner.Result#getFailures()

The following examples show how to use org.junit.runner.Result#getFailures() . 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: PropertyIndexingTests.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public static void main(String []argv)
{
	JUnitCore junit = new JUnitCore();
	Result result = null;
	do
	{
		result = junit.run(Request.method(PropertyIndexingTests.class, "derivedPropertyIndexing"));
	} while (result.getFailureCount() == 0 && false);
	System.out.println("Failures " + result.getFailureCount());
	if (result.getFailureCount() > 0)
	{
		for (Failure failure : result.getFailures())
		{
			failure.getException().printStackTrace();
		}
	}
	System.exit(0);
}
 
Example 2
Source File: TraversalsTests.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public static void main(String []argv)
{
	int maxIterations = 10;
    JUnitCore junit = new JUnitCore();
    Result result = null;
    int iter = 0;
    do
    {
    	result = junit.run(Request.method(TraversalsTests.class, "testDepthFirstOnCircle"));
    	iter++;
    	System.out.println("Failures " + result.getFailureCount());
     if (result.getFailureCount() > 0)
     {
         for (Failure failure : result.getFailures())
         {
             failure.getException().printStackTrace();
         }
     }
    } while (result.getFailureCount() == 0 && iter < maxIterations);
}
 
Example 3
Source File: JUnitNologExternalExecutor.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String createOutput(Result r) {
	String out = "[";
	int nr_failures = 0;
	try {
		for (Failure f : r.getFailures()) {
			String s = failureMessage(f);
			if (!s.startsWith("warning")) {
				nr_failures++;
			}
		}
	} catch (Exception e) {
		// We do not care about this exception,
	}
	out = out + "]";
	return (OUTSEP + r.getRunCount() + OUTSEP + nr_failures + OUTSEP + "" + OUTSEP);
}
 
Example 4
Source File: JUnitExternalExecutor.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public String createOutput(Result r) {
	String out = "[";
	int count = 0;
	int failures = 0;
	try {
		for (Failure f : r.getFailures()) {
			String s = failureMessage(f);
			if (!s.startsWith("warning")) {
				failures++;
			}
			out += s + "-,";
			count++;
			if (count > 10) {
				out += "...and " + (r.getFailureCount() - 10) + " failures more,";
				// break;
			}
		}
	} catch (Exception e) {
		// We do not care about this exception,
	}
	out = out + "]";
	return (OUTSEP + r.getRunCount() + OUTSEP + failures + OUTSEP + out + OUTSEP);
}
 
Example 5
Source File: End2EndTestDriver.java    From phoenix with Apache License 2.0 6 votes vote down vote up
void printSummary(Result result){
    Set<String> failures = new HashSet<String>();
    for(Failure f : result.getFailures()){
        failures.add(f.getTestHeader());
    }
    fWriter.println();
    fWriter.println("==== Test Summary ====");
    String status;
    for(String curTest : completes){
        status = "passed";
        if(failures.contains(curTest)) {
            status = "failed";
        }
        fWriter.println(curTest + "   " + status + "!");
    }
}
 
Example 6
Source File: TestFailIfUnreferencedFiles.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailIfUnreferencedFiles() {
  Result r = JUnitCore.runClasses(Nested1.class);
  RandomizedTest.assumeTrue("Ignoring nested test, very likely zombie threads present.", 
      r.getIgnoreCount() == 0);

  // We are suppressing output anyway so dump the failures.
  for (Failure f : r.getFailures()) {
    System.out.println(f.getTrace());
  }

  Assert.assertEquals("Expected exactly one failure.", 
      1, r.getFailureCount());
  Assert.assertTrue("Expected unreferenced files assertion.", 
      r.getFailures().get(0).getTrace().contains("unreferenced files:"));
}
 
Example 7
Source File: TestRequestBuilderTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
/** Test that {@link SdkSuppress} filters tests as appropriate when codeName specified */
@Test
public void testSdkSuppress_codeName() throws Exception {
  MockitoAnnotations.initMocks(this);
  TestRequestBuilder b = createBuilder(mockDeviceBuild);
  when(mockDeviceBuild.getSdkVersionInt()).thenReturn(29);
  when(mockDeviceBuild.getCodeName()).thenReturn("R");
  Request request = b.addTestClass(SampleSdkSuppress.class.getName()).build();
  JUnitCore testRunner = new JUnitCore();
  Result result = testRunner.run(request);

  Set<String> expected =
      new HashSet<>(
          Arrays.asList(
              "min29CodeNameR", "min20CodeNameR", "noSdkSuppress", "min15", "min16", "min17"));
  Assert.assertEquals(expected.size(), result.getRunCount());
  for (Failure f : result.getFailures()) {
    assertTrue(
        "Fail! " + expected + " doesn't contain \"" + f.getMessage() + "\" ",
        expected.contains(f.getMessage()));
  }
}
 
Example 8
Source File: JUnitRunner.java    From h2o-2 with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  try {
    H2O.main(args);
    TestUtil.stall_till_cloudsize(3);
    List<Class> tests = JUnitRunner.all();
    Result r = org.junit.runner.JUnitCore.runClasses(tests.toArray(new Class[0]));
    if( r.getFailureCount() == 0 ) {
      System.out.println("Successfully ran the following tests in " + (r.getRunTime() / 1000) + "s");
      for( Class c : tests )
        System.out.println(c.getName());
    } else {
      for( Failure f : r.getFailures() ) {
        System.err.println(f.getDescription());
        if( f.getException() != null )
          f.getException().printStackTrace();
      }
    }
    System.exit(r.getFailureCount());
  } catch( Throwable t ) {
    t.printStackTrace();
    System.exit(1);
  }
}
 
Example 9
Source File: RunJUnit4TestsFromJava.java    From tutorials with MIT License 5 votes vote down vote up
public static void runSuiteOfClasses() {
    JUnitCore junit = new JUnitCore();
    junit.addListener(new TextListener(System.out));
    Result result = junit.run(MyTestSuite.class);

    for (Failure failure : result.getFailures()) {
        System.out.println(failure.toString());
    }

    resultReport(result);
}
 
Example 10
Source File: TestRunner.java    From JSON-Java-unit-test with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
   Result result = JUnitCore.runClasses(JunitTestSuite.class);
   for (Failure failure : result.getFailures()) {
      System.out.println(failure.toString());
   }
   System.out.println(result.wasSuccessful());
}
 
Example 11
Source File: JPLTestSuiteRunner.java    From packages-jpl with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void main(String[] args) {
    Result result = JUnitCore.runClasses(JPLTestSuite.class);

    for (Failure failure : result.getFailures()) {
        System.out.println(failure.toString());
        failure.getException().printStackTrace();
    }

    System.out.println("********* Test successful? " + result.wasSuccessful());
}
 
Example 12
Source File: TestRunner.java    From burlap with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
   Result result = JUnitCore.runClasses(TestSuite.class);
   for (Failure failure : result.getFailures()) {
      System.out.println(failure.toString());
   }
   System.out.println(result.wasSuccessful());
}
 
Example 13
Source File: TestRequestBuilderTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
private static void ensureNoTestsFailed(Result result, int expectedTestCount) {
  Assert.assertEquals(expectedTestCount, result.getRunCount());
  List<Failure> failures = result.getFailures();
  try {
    Assert.assertEquals("No tests should have been executed", 0, failures.size());
  } catch (AssertionError e) {
    for (Failure failure : failures) {
      e.addSuppressed(failure.getException());
    }
    throw e;
  }
}
 
Example 14
Source File: TestRunner.java    From javase with MIT License 5 votes vote down vote up
public static void main(String[] args) {
   Result result = JUnitCore.runClasses(JunitTestSuite.class);
		
   for (Failure failure : result.getFailures()) {
      System.out.println(failure.toString());
   }
		
   System.out.println(result.wasSuccessful());
}
 
Example 15
Source File: MessageUtilTestJUnitRunner.java    From javase with MIT License 5 votes vote down vote up
public static void main(String[] args) {
   Result result = JUnitCore.runClasses(MessageUtilTestJUnit.class);
		
   for (Failure failure : result.getFailures()) {
      System.out.println(failure.toString());
   }
		
   System.out.println(result.wasSuccessful());
}
 
Example 16
Source File: ThreadsRunAllTestsHalfManualTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void run() {
    Result result = JUnitCore.runClasses(
            EqualsTest.class,
            ListUtilTest.class,
            MockingProgressImplTest.class,
            TimesTest.class,
            MockHandlerImplTest.class,
            AllInvocationsFinderTest.class,
            ReturnsEmptyValuesTest.class,
            NumberOfInvocationsCheckerTest.class,
            DefaultRegisteredInvocationsTest.class,
            MissingInvocationCheckerTest.class,
            NumberOfInvocationsInOrderCheckerTest.class,
            MissingInvocationInOrderCheckerTest.class,
            ClassImposterizerTest.class,
            InvocationMatcherTest.class,
            InvocationsFinderTest.class,
            InvocationImplTest.class,
            MockitoTest.class,
            MockUtilTest.class,
            ReporterTest.class,
            MockitoAssertionErrorTest.class,
            MockitoExceptionTest.class,
            StackTraceFilteringTest.class,
            BridgeMethodPuzzleTest.class,
            OverloadingPuzzleTest.class,
            InvalidUsageTest.class,
            UsingVarargsTest.class,
            CustomMatchersTest.class,
            ComparableMatchersTest.class,
            InvalidUseOfMatchersTest.class,
            MatchersTest.class,
            MatchersToStringTest.class,
            VerificationAndStubbingUsingMatchersTest.class,
            BasicStubbingTest.class,
            ReturningDefaultValuesTest.class,
            StubbingWithThrowablesTest.class,
            AtMostXVerificationTest.class,
            BasicVerificationTest.class,
            ExactNumberOfTimesVerificationTest.class,
            VerificationInOrderTest.class,
            NoMoreInteractionsVerificationTest.class,
            SelectedMocksInOrderVerificationTest.class,
            VerificationOnMultipleMocksUsingMatchersTest.class,
            VerificationUsingMatchersTest.class,
            RelaxedVerificationInOrderTest.class,
            DescriptiveMessagesWhenVerificationFailsTest.class,
            DescriptiveMessagesWhenTimesXVerificationFailsTest.class,
            BasicVerificationInOrderTest.class,
            VerificationInOrderMixedWithOrdiraryVerificationTest.class,
            DescriptiveMessagesOnVerificationInOrderErrorsTest.class,
            InvalidStateDetectionTest.class,
            ReplacingObjectMethodsTest.class,
            ClickableStackTracesTest.class,
            ExampleTest.class,
            PointingStackTraceToActualInvocationTest.class,
            VerificationInOrderFromMultipleThreadsTest.class,
            ResetTest.class,
            ReturnsGenericDeepStubsTest.class
        );
        
        if (!result.wasSuccessful()) {
            System.err.println("Thread[" + Thread.currentThread().getId() + "]: error!");
            List<Failure> failures = result.getFailures();
            System.err.println(failures.size());
            for (Failure failure : failures) {
                System.err.println(failure.getTrace());
                failed = true;
            }
        }
}
 
Example 17
Source File: NALTest.java    From opennars with MIT License 4 votes vote down vote up
public static void runTests(final Class c) {

        tests.clear();
        scores.clear();

        final Result result = JUnitCore.runClasses(new ParallelComputer(true, true), c);
              
        
        for (final Failure f : result.getFailures()) {
            final String test = f.getMessage().substring(f.getMessage().indexOf("/nal/single_step") + 8, f.getMessage().indexOf(".nal"));
            
            tests.put(test, false);
        }

        /* commented because name.split() is broken for a special case in NalTestMetrics
        final int[] levelSuccess = new int[10];
        final int[] levelTotals = new int[10];
        
        for (final Map.Entry<String, Boolean> e : tests.entrySet()) {
            final String name = e.getKey();
            int level = 0;
            level = Integer.parseInt(name.split("\\.")[0]);
            levelTotals[level]++;
            if (e.getValue()) {
                levelSuccess[level]++;
            }
        }
        
        if (showReport) {
            int totalSucceeded = 0, total = 0;
            for (int i = 0; i < 9; i++) {
                final float rate = (levelTotals[i] > 0) ? ((float)levelSuccess[i]) / levelTotals[i] : 0;
                final String prefix = (i > 0) ? ("NAL" + i) : "Other";

                System.out.println(prefix + ": " + (rate*100.0) + "%  (" + levelSuccess[i] + "/" + levelTotals[i] + ")" );
                totalSucceeded += levelSuccess[i];
                total += levelTotals[i];
            }
            System.out.println(totalSucceeded + " / " + total);
        }
         */
    }
 
Example 18
Source File: HibernateCriteriaTestRunner.java    From tutorials with MIT License 4 votes vote down vote up
public static void main(final String[] args) {
    Result result = JUnitCore.runClasses(HibernateCriteriaTestSuite.class);
    for (Failure failure : result.getFailures()) {

    }
}
 
Example 19
Source File: ParcelableResult.java    From android-test with Apache License 2.0 4 votes vote down vote up
public ParcelableResult(Result result) {
  failures = new ArrayList<>();
  for (org.junit.runner.notification.Failure failure : result.getFailures()) {
    failures.add(new ParcelableFailure(failure));
  }
}
 
Example 20
Source File: JUnit4TestRunner.java    From quickperf with Apache License 2.0 3 votes vote down vote up
@Override
public TestIssue executeTestMethod(Class<?> testClass, String methodName) {

    Request junitRequestOfMethod = Request.method(testClass, methodName);

    Result testResult = new JUnitCore().run(junitRequestOfMethod);

    List<Failure> jUnit4Failures = testResult.getFailures();

    List<Throwable> jUnit4failuresAsThrowables = convertJUnit4FailuresToThrowables(jUnit4Failures);

    return  TestIssue.buildInNewJvmFrom(jUnit4failuresAsThrowables);

}