1 package org.robolectric.android; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 import javax.annotation.Nonnull; 6 import org.junit.runner.notification.Failure; 7 import org.junit.runner.notification.RunListener; 8 import org.junit.runner.notification.RunNotifier; 9 import org.junit.runners.model.InitializationError; 10 import org.robolectric.RobolectricTestRunner; 11 12 public class FailureListener extends RunListener { 13 @Nonnull runTests(Class<?> testClass)14 public static List<Failure> runTests(Class<?> testClass) throws InitializationError { 15 RunNotifier notifier = new RunNotifier(); 16 FailureListener failureListener = new FailureListener(); 17 notifier.addListener(failureListener); 18 new RobolectricTestRunner(testClass).run(notifier); 19 return failureListener.failures; 20 } 21 22 public final List<Failure> failures = new ArrayList<>(); 23 24 @Override testFailure(Failure failure)25 public void testFailure(Failure failure) throws Exception { 26 failures.add(failure); 27 } 28 29 @Override testAssumptionFailure(Failure failure)30 public void testAssumptionFailure(Failure failure) { 31 failures.add(failure); 32 } 33 } 34