Java Code Examples for org.junit.runner.Request#getRunner()
The following examples show how to use
org.junit.runner.Request#getRunner() .
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: JUnitTestClassExecuter.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void runTestClass(String testClassName) throws ClassNotFoundException { final Class<?> testClass = Class.forName(testClassName, false, applicationClassLoader); Request request = Request.aClass(testClass); if (options.hasCategoryConfiguration()) { Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() { public Class<?> transform(final String original) { try { return applicationClassLoader.loadClass(original); } catch (ClassNotFoundException e) { throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e); } } }; request = request.filterWith(new CategoryFilter( CollectionUtils.collect(options.getIncludeCategories(), transformer), CollectionUtils.collect(options.getExcludeCategories(), transformer) )); } if (!options.getIncludedTests().isEmpty()) { request = request.filterWith(new MethodNameFilter(options.getIncludedTests())); } Runner runner = request.getRunner(); //In case of no matching methods junit will return a ErrorReportingRunner for org.junit.runner.manipulation.Filter.class. //Will be fixed with adding class filters if (!org.junit.runner.manipulation.Filter.class.getName().equals(runner.getDescription().getDisplayName())) { RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); runner.run(notifier); } }
Example 2
Source File: JUnitTestClassExecuter.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void runTestClass(String testClassName) throws ClassNotFoundException { final Class<?> testClass = Class.forName(testClassName, true, applicationClassLoader); Request request = Request.aClass(testClass); if (options.hasCategoryConfiguration()) { Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() { public Class<?> transform(final String original) { try { return applicationClassLoader.loadClass(original); } catch (ClassNotFoundException e) { throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e); } } }; request = request.filterWith(new CategoryFilter( CollectionUtils.collect(options.getIncludeCategories(), transformer), CollectionUtils.collect(options.getExcludeCategories(), transformer) )); } if (!options.getIncludedTests().isEmpty()) { request = request.filterWith(new MethodNameFilter(options.getIncludedTests())); } Runner runner = request.getRunner(); //In case of no matching methods junit will return a ErrorReportingRunner for org.junit.runner.manipulation.Filter.class. //Will be fixed with adding class filters if (!org.junit.runner.manipulation.Filter.class.getName().equals(runner.getDescription().getDisplayName())) { RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); runner.run(notifier); } }
Example 3
Source File: GuidedFuzzing.java From JQF with BSD 2-Clause "Simplified" License | 5 votes |
/** * Runs the guided fuzzing loop for a resolved class. * * <p>The test class must be annotated with <tt>@RunWith(JQF.class)</tt> * and the test method must be annotated with <tt>@Fuzz</tt>.</p> * * <p>Once this method is invoked, the guided fuzzing loop runs continuously * until the guidance instance decides to stop by returning <tt>false</tt> * for {@link Guidance#hasInput()}. Until the fuzzing stops, this method * cannot be invoked again (i.e. at most one guided fuzzing can be running * at any time in a single JVM instance).</p> * * @param testClass the test class containing the test method * @param testMethod the test method to execute in the fuzzing loop * @param guidance the fuzzing guidance * @param out an output stream to log Junit messages * @throws IllegalStateException if a guided fuzzing run is currently executing * @return the Junit-style test result */ public synchronized static Result run(Class<?> testClass, String testMethod, Guidance guidance, PrintStream out) throws IllegalStateException { // Ensure that the class uses the right test runner RunWith annotation = testClass.getAnnotation(RunWith.class); if (annotation == null || !annotation.value().equals(JQF.class)) { throw new IllegalArgumentException(testClass.getName() + " is not annotated with @RunWith(JQF.class)"); } // Set the static guided instance setGuidance(guidance); // Register callback SingleSnoop.setCallbackGenerator(guidance::generateCallBack); // Create a JUnit Request Request testRequest = Request.method(testClass, testMethod); // Instantiate a runner (may return an error) Runner testRunner = testRequest.getRunner(); // Start tracing for the test method SingleSnoop.startSnooping(testClass.getName() + "#" + testMethod); // Run the test and make sure to de-register the guidance before returning try { JUnitCore junit = new JUnitCore(); if (out != null) { junit.addListener(new TextListener(out)); } return junit.run(testRunner); } finally { unsetGuidance(); } }
Example 4
Source File: HybrisJUnitIntegrationTestLoader.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 5 votes |
private ITestReference createFilteredTest(Class<?> clazz, String testName, String[] failureNames) { DescriptionMatcher matcher= DescriptionMatcher.create(clazz, testName); SubForestFilter filter= new SubForestFilter(matcher); Request request= sortByFailures(Request.classWithoutSuiteMethod(clazz).filterWith(filter), failureNames); Runner runner= request.getRunner(); Description description= getRootDescription(runner, matcher); return new HybrisJUnitTestReference(runner, description); }
Example 5
Source File: TestRunner.java From spoon-examples with GNU General Public License v2.0 | 5 votes |
public static List<Failure> runTest(String fullQualifiedName, String testCaseName, String[] classpath) throws MalformedURLException, ClassNotFoundException { ClassLoader classLoader = new URLClassLoader( arrayStringToArrayUrl.apply(classpath), ClassLoader.getSystemClassLoader() ); Request request = Request.method(classLoader.loadClass(fullQualifiedName), testCaseName); Runner runner = request.getRunner(); RunNotifier fNotifier = new RunNotifier(); final TestListener listener = new TestListener(); fNotifier.addFirstListener(listener); fNotifier.fireTestRunStarted(runner.getDescription()); runner.run(fNotifier); return listener.getTestFails(); }
Example 6
Source File: TestRunner.java From spoon-examples with GNU General Public License v2.0 | 5 votes |
public static List<Failure> runTest(String fullQualifiedName, String[] classpath) throws MalformedURLException, ClassNotFoundException { ClassLoader classLoader = new URLClassLoader( arrayStringToArrayUrl.apply(classpath), ClassLoader.getSystemClassLoader() ); Request request = Request.classes(classLoader.loadClass(fullQualifiedName)); Runner runner = request.getRunner(); RunNotifier fNotifier = new RunNotifier(); final TestListener listener = new TestListener(); fNotifier.addFirstListener(listener); fNotifier.fireTestRunStarted(runner.getDescription()); runner.run(fNotifier); return listener.getTestFails(); }
Example 7
Source File: JUnitTestClassExecuter.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
private void runTestClass(String testClassName) throws ClassNotFoundException { final Class<?> testClass = Class.forName(testClassName, false, applicationClassLoader); Request request = Request.aClass(testClass); if (options.hasCategoryConfiguration()) { Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() { public Class<?> transform(final String original) { try { return applicationClassLoader.loadClass(original); } catch (ClassNotFoundException e) { throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e); } } }; request = request.filterWith(new CategoryFilter( CollectionUtils.collect(options.getIncludeCategories(), transformer), CollectionUtils.collect(options.getExcludeCategories(), transformer) )); } if (!options.getIncludedTests().isEmpty()) { request = request.filterWith(new MethodNameFilter(options.getIncludedTests())); } Runner runner = request.getRunner(); //In case of no matching methods junit will return a ErrorReportingRunner for org.junit.runner.manipulation.Filter.class. //Will be fixed with adding class filters if (!org.junit.runner.manipulation.Filter.class.getName().equals(runner.getDescription().getDisplayName())) { RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); runner.run(notifier); } }
Example 8
Source File: JUnitTestClassExecuter.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
private void runTestClass(String testClassName) throws ClassNotFoundException { final Class<?> testClass = Class.forName(testClassName, true, applicationClassLoader); Request request = Request.aClass(testClass); if (options.hasCategoryConfiguration()) { Transformer<Class<?>, String> transformer = new Transformer<Class<?>, String>() { public Class<?> transform(final String original) { try { return applicationClassLoader.loadClass(original); } catch (ClassNotFoundException e) { throw new InvalidUserDataException(String.format("Can't load category class [%s].", original), e); } } }; request = request.filterWith(new CategoryFilter( CollectionUtils.collect(options.getIncludeCategories(), transformer), CollectionUtils.collect(options.getExcludeCategories(), transformer) )); } if (!options.getIncludedTests().isEmpty()) { request = request.filterWith(new MethodNameFilter(options.getIncludedTests())); } Runner runner = request.getRunner(); //In case of no matching methods junit will return a ErrorReportingRunner for org.junit.runner.manipulation.Filter.class. //Will be fixed with adding class filters if (!org.junit.runner.manipulation.Filter.class.getName().equals(runner.getDescription().getDisplayName())) { RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); runner.run(notifier); } }
Example 9
Source File: TestRequestBuilderTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void testShardingFilter_Empty() { Request request = createBuilder() .addShardingFilter(97, 0) .addTestClass(TestShardingFilterTest.class.getName()) .build(); Runner runner = request.getRunner(); JUnitCore testRunner = new JUnitCore(); Result result = testRunner.run(runner); Assert.assertEquals(0, result.getRunCount()); }
Example 10
Source File: HybrisJUnitIntegrationTestLoader.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 4 votes |
private ITestReference createUnfilteredTest(Class<?> clazz, String[] failureNames) { Request request= sortByFailures(Request.aClass(clazz), failureNames); Runner runner= request.getRunner(); Description description= runner.getDescription(); return new HybrisJUnitTestReference(runner, description); }
Example 11
Source File: JUnit4Runner.java From bazel with Apache License 2.0 | 4 votes |
private static Request applyFilter(Request request, Filter filter) throws NoTestsRemainException { Runner runner = request.getRunner(); new SuiteTrimmingFilter(filter).apply(runner); return Request.runner(runner); }
Example 12
Source File: Filters.java From bazel with Apache License 2.0 | 3 votes |
/** * Returns a Request that only contains those tests that should run when * a filter is applied, filtering out all empty suites.<p> * * Note that if the request passed into this method caches its runner, * that runner will be modified to use the given filter. To be safe, * do not use the passed-in request after calling this method. * * @param request Request to filter * @param filter Filter to apply * @return request * @throws NoTestsRemainException if the applying the filter removes all tests */ public static Request apply(Request request, Filter filter) throws NoTestsRemainException { filter = new SuiteTrimmingFilter(filter); Runner runner = request.getRunner(); filter.apply(runner); return Request.runner(runner); }
Example 13
Source File: MemoizingRequest.java From bazel with Apache License 2.0 | 2 votes |
/** * Creates the runner. This method is called at most once. * Subclasses can override this method for different behavior. * The default implementation returns the runner created by the delegate. * * @param delegate request to delegate to * @return runner */ Runner createRunner(Request delegate) { return delegate.getRunner(); }