private Runner buildRunner(Description each) { if (each.toString().equals("TestSuite with 0 tests")) { return Suite.emptySuite(); } if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) { // This is cheating, because it runs the whole class // to get the warning for this method, but we can't do better, // because JUnit 3.8's // thrown away which method the warning is for. return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each))); } Class<?> type = each.getTestClass(); if (type == null) { throw new RuntimeException("Can't build a runner from description [" + each + "]"); } String methodName = each.getMethodName(); if (methodName == null) { return Request.aClass(type).getRunner(); } return Request.method(type, methodName).getRunner(); }
private Runner buildRunner(Description each) { if (each.toString().equals("TestSuite with 0 tests")) { return Suite.emptySuite(); } if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) { // This is cheating, because it runs the whole class // to get the warning for this method, but we can't do better, // because JUnit 3.8's // thrown away which method the warning is for. return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each))); } Class<?> type = each.getTestClass(); if (type == null) { throw new RuntimeException("Can't build a runner from description [" + each + "]"); } String methodName = each.getMethodName(); if (methodName == null) { return Request.aClass(type).getRunner(); } return Request.method(type, methodName).getRunner(); }
private Runner buildRunner(Description each) { if (each.toString().equals("TestSuite with 0 tests")) { return Suite.emptySuite(); } if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) { // This is cheating, because it runs the whole class // to get the warning for this method, but we can't do better, // because JUnit 3.8's // thrown away which method the warning is for. return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each))); } Class<?> type = each.getTestClass(); if (type == null) { throw new RuntimeException("Can't build a runner from description [" + each + "]"); } String methodName = each.getMethodName(); if (methodName == null) { return Request.aClass(type).getRunner(); } return Request.method(type, methodName).getRunner(); }
private Runnable createRunnable(Class<?> testClass, String testMathod) { return () -> { LOGGER.info(Thread.currentThread().getName() + " Parallel Junit test- *Start. Time = " + now()); Result result = (new JUnitCore()).run(Request.method(testClass, testMathod)); LOGGER.info(Thread.currentThread().getName() + " Parallel Junit test- * End. Time = " + now()); if (result.wasSuccessful()) { passedCounter.incrementAndGet(); } else { failedCounter.incrementAndGet(); } }; }
private static List<JUnit4TestReference> getRequestForOneMethod( String suite, int separatorIndex) { try { Class suiteClass = Class.forName(suite.substring(0, separatorIndex)); String method = suite.substring(separatorIndex + 1); Request request = Request.method(suiteClass, method); Runner runner = request.getRunner(); return singletonList(new JUnit4TestReference(runner, runner.getDescription())); } catch (ClassNotFoundException e) { System.err.print("No test found to run."); return emptyList(); } }
private static void runTest(String test) { try { String[] classAndMethod = test.split("#"); System.out.println(test); Request request = Request.method(Class.forName(classAndMethod[0]), classAndMethod[1]); JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); junit.run(request); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }
/** * Run a single method test * * @param jUnitCore * @param className * @param method */ protected void runMethodOnly(JUnitCore jUnitCore, String className, String method) { try { jUnitCore.run(Request.method(Class.forName(className), method)); } catch (ClassNotFoundException e) { error("Test class not found: " + className); printStackTrace(e); } }
/** * Run a single method test * * @param jUnitCore * @param className * @param method */ protected void runMethodOnly(JUnitCore jUnitCore, String className, String method) { try { jUnitCore.run(Request.method(Class.forName(className), method)); } catch (ClassNotFoundException e) { error("Test class not found: " + className); printStackTrace(e); } }
@Override public Result call() throws Exception { JUnitCore runner = new JUnitCore(); runner.addListener(listener); Request request = Request.method(testClassFromCustomClassLoader(), testCaseName()); try { return runner.run(request); } catch (Throwable e) { throw new RuntimeException(e); } }
@Override public Result call() throws Exception { JUnitCore runner = new JUnitCore(); runner.addListener(listener); Request request = Request.method(testClassFromCustomClassLoader(), testCaseName()); try { return runner.run(request); } catch (Throwable e) { throw new RuntimeException(e); } }
private Runner buildRunner(Description each) { if (each.toString().equals("TestSuite with 0 tests")) { return Suite.emptySuite(); } if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) { // This is cheating, because it runs the whole class // to get the warning for this method, but we can't do better, // because JUnit 3.8's // thrown away which method the warning is for. return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each))); } Class<?> type = each.getTestClass(); if (type == null) { throw new RuntimeException("Can't build a runner from description [" + each + "]"); } String methodName = each.getMethodName(); if (methodName == null) { return Request.aClass(type).getRunner(); } return Request.method(type, methodName).getRunner(); }
private Runner buildRunner(Description each) { if (each.toString().equals("TestSuite with 0 tests")) { return Suite.emptySuite(); } if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) { // This is cheating, because it runs the whole class // to get the warning for this method, but we can't do better, // because JUnit 3.8's // thrown away which method the warning is for. return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each))); } Class<?> type = each.getTestClass(); if (type == null) { throw new RuntimeException("Can't build a runner from description [" + each + "]"); } String methodName = each.getMethodName(); if (methodName == null) { return Request.aClass(type).getRunner(); } return Request.method(type, methodName).getRunner(); }
private Runner buildRunner(Description each) { if (each.toString().equals("TestSuite with 0 tests")) { return Suite.emptySuite(); } if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) { // This is cheating, because it runs the whole class // to get the warning for this method, but we can't do better, // because JUnit 3.8's // thrown away which method the warning is for. return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each))); } Class<?> type = each.getTestClass(); if (type == null) { throw new RuntimeException("Can't build a runner from description [" + each + "]"); } String methodName = each.getMethodName(); if (methodName == null) { return Request.aClass(type).getRunner(); } return Request.method(type, methodName).getRunner(); }
private Runner buildRunner(Description each) { if (each.toString().equals("TestSuite with 0 tests")) { return Suite.emptySuite(); } if (each.toString().startsWith(MALFORMED_JUNIT_3_TEST_CLASS_PREFIX)) { // This is cheating, because it runs the whole class // to get the warning for this method, but we can't do better, // because JUnit 3.8's // thrown away which method the warning is for. return new JUnit38ClassRunner(new TestSuite(getMalformedTestClass(each))); } Class<?> type = each.getTestClass(); if (type == null) { throw new RuntimeException("Can't build a runner from description [" + each + "]"); } String methodName = each.getMethodName(); if (methodName == null) { return Request.aClass(type).getRunner(); } return Request.method(type, methodName).getRunner(); }
@Override public Result call() throws Exception { JUnitCore runner = new JUnitCore(); runner.addListener(listener); Request request = Request.method(testClassFromCustomClassLoader(), testCaseName()); return runner.run(request); }
@Override public Result call() throws Exception { JUnitCore runner = new JUnitCore(); runner.addListener(listener); Request request = Request.method(testClassFromCustomClassLoader(), testCaseName()); return runner.run(request); }
/** * . * @param args . * @throws ClassNotFoundException . */ public static void main(String... args) throws ClassNotFoundException { int retCode = 0; String resultMessage = "SUCCESS"; String[] classAndMethod = args[0].split("#"); Request request = Request.method(Class.forName(classAndMethod[0]), classAndMethod[1]); Result result = new JUnitCore().run(request); if (!result.wasSuccessful()) { retCode = 1; resultMessage = "FAILURE"; } System.out.println(resultMessage); System.exit(retCode); } }
private void verifyExceptionThrownByDiffAssertionRule(boolean shouldBeThrown, String methodName) { Request assertStateApi = Request.method(NoDiffAssertionRuleTest.class, methodName); Result result = new JUnitCore().run(assertStateApi); if (shouldBeThrown) { assertThat(result.getFailures()).hasSize(1); verifyExceptionAssertionErrorWithDiff(result.getFailures().get(0).getException()); } else { assertThat(result.getFailures()).isEmpty(); } }
public TestResult execute(Class<?> testClass, String methodName) { DeployableTestBuilder.setProfile(getProfile()); JUnitCore runner = new JUnitCore(); ExpectedExceptionHolder exceptionHolder = new ExpectedExceptionHolder(); runner.addListener(exceptionHolder); for (RunListener listener : getRunListeners()) runner.addListener(listener); Result result = runner.run(Request.method(testClass, methodName)); DeployableTestBuilder.clearProfile(); return convertToTestResult(result, exceptionHolder.getException()); }
public static void run(Configuration configuration, Class<?> clazz, String methodName) { try { Request request = null; if (clazz!=null && methodName!=null) { request = Request.method(clazz, methodName); } else { Suite suite = new Suite(new JUnit4Builder(), API_TEST_CLASSES); request = Request.runner(suite); } Configuration originalConfiguration = WorkflowTest.cachedConfiguration; WorkflowTest.cachedConfiguration = configuration; JUnitCore junitCore = new JUnitCore(); Result result = junitCore.run(request); WorkflowTest.cachedConfiguration = originalConfiguration; checkResult(result); } catch (Exception e) { throw new RuntimeException(e); } }