@Override public void run() throws EngineException { try { Result result = jUnitCore.run(new Computer(), suite.tests()); System.out.println( String.format( "Total tests run: %s, Failures: %s, Skips: %s", result.getRunCount(), result.getFailureCount(), result.getIgnoreCount() ) ); System.exit(result.wasSuccessful() ? 0 : -1); } catch (SuiteException e) { throw new EngineException("Some problem occurs in the Junit4 engine", e); } }
@Test public void testSystem() throws Throwable { Computer computer = new Computer(); JUnitCore jUnitCore = new JUnitCore(); ByteArrayOutputStream capture = new ByteArrayOutputStream(); final PrintStream printStream = new PrintStream(capture); TextListener listener = new TextListener(printStream); jUnitCore.addListener(listener); PrintStream systemOut = System.out; System.setOut(printStream); try { jUnitCore.run(computer, ExampleTest.class); } finally { System.setOut(systemOut); } String output = capture.toString("UTF-8"); output = normalizeOutput(output); String expectedOutput = getResource("/CompositeTest.testSystem.expected.txt"); Assert.assertEquals(expectedOutput, output); }
private void execClass(final TestClassExecutionData o) { classData = o; CLASS_DATA_IN_CONTEXT.set(o); try { HtmlRunReporter reporter = o.getHtmlRunReporter(); reporter.hiddenBeforeTestClassExecution(); core.addListener(reporter); Result result = core.run(Computer.serial(), o.getTestClass()); for (Failure failure : result.getFailures()) { LOGGER.debug(failure.toString()); } classData.setCountOfRuns(result.getRunCount()); core.removeListener(reporter); reporter.hiddenAfterTestClassExecution(); } catch (Throwable e) { //this is gas LOGGER.debug("Thread: got EX during JUnitCore execution.", e); } CLASS_DATA_IN_CONTEXT.set(null); classData = null; }
/** * Returns status of JUnite tests execution. * * @return the status * @throws KernelException if any error occurs during JUnit tests execution. */ @Override public Status status() throws KernelException { try { return new JunitStatus(this.junit.run(new Computer(), this.suiteForRun.tests())); } catch (SuiteException e) { throw new KernelException("Some problem occurs in the Junit4Kernel", e); } }
@Override public void didBecomeActive(UIApplication application) { super.didBecomeActive(application); NSException.registerDefaultJavaUncaughtExceptionHandler(); Computer computer = new Computer(); JUnitCore jUnitCore = new JUnitCore(); jUnitCore.addListener(new TextListener(System.out)); jUnitCore.run(computer, getTestClasses()); }
/** * Builds the {@link android.support.test.internal.runner.TestRequest} based on current contents of added classes and methods. * <p/> * If no classes have been explicitly added, will scan the classpath for all tests. */ public TestRequest build(Instrumentation instr, Bundle bundle) { if (mTestLoader.isEmpty()) { // no class restrictions have been specified. Load all classes loadClassesFromClassPath(); } Request request = classes( new AndroidRunnerParams(instr, bundle, mSkipExecution, mPerTestTimeout), new Computer(), mTestLoader.getLoadedClasses().toArray(new Class[0])); return new TestRequest(mTestLoader.getLoadFailures(), new LenientFilterRequest(request, mFilter)); }
@Test public void sortTestsInMultipleClasses() { Request request = Request.classes(Computer.serial(), TwoTests.class, TwoTests.class); fMax.run(request); List<Description> tests = fMax.sortedLeavesForTest(request); Description dontSucceed = Description.createTestDescription( TwoTests.class, "dontSucceed"); assertEquals(dontSucceed, tests.get(0)); assertEquals(dontSucceed, tests.get(1)); }
/** * Method to execute all tests * * @param filename: Filename for the properties file */ private static void runTests(String filename) { System.setProperty("PROPSFILENAME", filename); JUnitCore core = new JUnitCore(); core.run(new Computer(), AllTests.class); }
/** * Method to execute all tests * @param filename: Filename for the properties file */ private static void runTests(String filename) { System.setProperty("PROPSFILENAME", filename); JUnitCore core = new JUnitCore(); core.run(new Computer(), AllTests.class); }
private Result runJunitTestWithComputer(Computer computer, Class<?> clazz) { Result result = JUnitCore.runClasses(computer, clazz); List<Failure> failures = result.getFailures(); for(Failure failure : failures) { System.out.println(failure.getMessage()); } return result; }
@Override public void run() throws Throwable { Level stdOutLogLevel = Level.INFO; Level stdErrLogLevel = Level.WARNING; String unparsedStdOutLogLevel = System.getProperty(STD_OUT_LOG_LEVEL_PROPERTY); String unparsedStdErrLogLevel = System.getProperty(STD_ERR_LOG_LEVEL_PROPERTY); if (unparsedStdOutLogLevel != null) { stdOutLogLevel = Level.parse(unparsedStdOutLogLevel); } if (unparsedStdErrLogLevel != null) { stdErrLogLevel = Level.parse(unparsedStdErrLogLevel); } for (String className : testClassNames) { final Class<?> testClass = Class.forName(className); List<TestResult> results = new ArrayList<>(); RecordingFilter filter = new RecordingFilter(); if (mightBeATestClass(testClass)) { JUnitCore jUnitCore = new JUnitCore(); Runner suite = new Computer().getSuite(createRunnerBuilder(), new Class<?>[] {testClass}); Request request = Request.runner(suite); request = request.filterWith(filter); jUnitCore.addListener(new TestListener(results, stdOutLogLevel, stdErrLogLevel)); jUnitCore.run(request); } // Combine the results with the tests we filtered out List<TestResult> actualResults = combineResults(results, filter.filteredOut); writeResult(className, actualResults); } }
public static Computer classes() { return new ParallelComputer(true, false); }
public static Computer methods() { return new ParallelComputer(false, true); }
static Computer defaultComputer() { return new Computer(); }
@Test public void testCustomJUnitRunnerWithComputer() throws CompilationFailedException, IOException { String filename = "src/test/resources/groovy/GroovyRunnerTest.groovy"; Computer computer = new SeleniumComputer("http://www.papajohns.co.uk"); Result result = runJunitTestWithComputer(computer, getGroovyClass(filename)); assertEquals(0, result.getFailureCount()); }
/** * Run the tests contained in <code>classes</code>. Write feedback while the * tests are running and write stack traces for all failed tests after all * tests complete. This is similar to {@link #main(String[])}, but intended * to be used programmatically. * * @param computer * Helps construct Runners from classes * @param classes * Classes in which to find tests * @return a {@link Result} describing the details of the test run and the * failed tests. */ public static Result runClasses(Computer computer, Class<?>... classes) { return new MarathonTestRunner().run(computer, classes); }
/** * Run all the tests in <code>classes</code>. * * @param computer * Helps construct Runners from classes * @param classes * the classes containing tests * @return a {@link Result} describing the details of the test run and the * failed tests. */ public Result run(Computer computer, Class<?>... classes) { return run(Request.classes(computer, classes)); }