org.junit.runners.BlockJUnit4ClassRunner Java Examples
The following examples show how to use
org.junit.runners.BlockJUnit4ClassRunner.
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: LambdaTestSuite.java From lambda-selenium with MIT License | 6 votes |
protected static List<TestRequest> getTestRequests(String folderName, Filter filter) { List<TestRequest> requests = new ArrayList<>(); getTestClasses(folderName).forEach(testClass -> { try { new BlockJUnit4ClassRunner(testClass).getDescription().getChildren() .forEach(description -> { if (filter.shouldRun(description)) { TestRequest request = new TestRequest(description); request.setTestRunUUID(TestUUID.getTestUUID()); requests.add(request); } }); } catch (InitializationError e) { LOGGER.log(e); } }); return requests; }
Example #2
Source File: EjbWithMockitoRunner.java From testfun with Apache License 2.0 | 6 votes |
public EjbWithMockitoRunner(Class<?> klass) throws InvocationTargetException, InitializationError { runner = new BlockJUnit4ClassRunner(klass) { @Override protected Object createTest() throws Exception { Object test = super.createTest(); // init annotated mocks before tests MockitoAnnotations.initMocks(test); // inject annotated EJBs before tests injectEjbs(test); // Rollback any existing transaction before starting a new one TransactionUtils.rollbackTransaction(); TransactionUtils.endTransaction(true); // Start a new transaction TransactionUtils.beginTransaction(); return test; } }; }
Example #3
Source File: RunNotifierTest.java From spectrum with MIT License | 5 votes |
private RunNotifier runWithNotifier(Class<?> clazz) { RunNotifier notifier = mock(RunNotifier.class); try { new BlockJUnit4ClassRunner(clazz).run(notifier); } catch (InitializationError initializationError) { throw new RuntimeException("Cannot initialize test: " + initializationError.getMessage(), initializationError); } return notifier; }
Example #4
Source File: StackLocatorUtilTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testGetCallerClassViaAnchorClass() throws Exception { final Class<?> expected = BlockJUnit4ClassRunner.class; final Class<?> actual = StackLocatorUtil.getCallerClass(ParentRunner.class); // if this test fails in the future, it's probably because of a JUnit upgrade; check the new stack trace and // update this test accordingly assertSame(expected, actual); }
Example #5
Source File: StackLocatorUtilTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testGetCallerClassViaName() throws Exception { final Class<?> expected = BlockJUnit4ClassRunner.class; final Class<?> actual = StackLocatorUtil.getCallerClass("org.junit.runners.ParentRunner"); // if this test fails in the future, it's probably because of a JUnit upgrade; check the new stack trace and // update this test accordingly assertSame(expected, actual); }
Example #6
Source File: StackLocatorTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testGetCallerClassViaAnchorClass() throws Exception { final Class<?> expected = BlockJUnit4ClassRunner.class; final Class<?> actual = stackLocator.getCallerClass(ParentRunner.class); // if this test fails in the future, it's probably because of a JUnit upgrade; check the new stack trace and // update this test accordingly assertSame(expected, actual); }
Example #7
Source File: StackLocatorTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testGetCallerClassViaName() throws Exception { final Class<?> expected = BlockJUnit4ClassRunner.class; final Class<?> actual = stackLocator.getCallerClass("org.junit.runners.ParentRunner"); // if this test fails in the future, it's probably because of a JUnit upgrade; check the new stack trace and // update this test accordingly assertSame(expected, actual); }
Example #8
Source File: ConcurrentParameterized.java From at.info-knowledge-base with MIT License | 5 votes |
@Override protected List<Runner> getChildren() { for (Runner runner : super.getChildren()) { BlockJUnit4ClassRunner classRunner = (BlockJUnit4ClassRunner) runner; classRunner.setScheduler(scheduler); } return super.getChildren(); }
Example #9
Source File: JUnit45AndHigherRunnerImpl.java From astor with GNU General Public License v2.0 | 5 votes |
public JUnit45AndHigherRunnerImpl(Class<?> klass) throws InitializationError { runner = new BlockJUnit4ClassRunner(klass) { protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) { // init annotated mocks before tests MockitoAnnotations.initMocks(target); return super.withBefores(method, target, statement); } }; }
Example #10
Source File: JUnit45AndHigherRunnerImpl.java From astor with GNU General Public License v2.0 | 5 votes |
public JUnit45AndHigherRunnerImpl(Class<?> klass) throws InitializationError { runner = new BlockJUnit4ClassRunner(klass) { protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) { // init annotated mocks before tests MockitoAnnotations.initMocks(target); return super.withBefores(method, target, statement); } }; }
Example #11
Source File: JFixtureJUnitRunner.java From jfixture with MIT License | 5 votes |
public JFixtureJUnitRunner(Class<?> clazz) throws InitializationError { this.runner = new BlockJUnit4ClassRunner(clazz) { @Override protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) { Statement base = super.withBefores(method, target, statement); return new JUnitJFixtureStatement(base, target, new JFixture()); } }; }
Example #12
Source File: AllExceptIgnoredTestRunnerBuilder.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public Runner runnerForClass(Class<?> testClass) throws Throwable { try { return new BlockJUnit4ClassRunner(testClass); } catch (Throwable t) { //failed to instantiate BlockJUnitRunner. try deprecated JUnitRunner (for JUnit < 4.5) try { Class<Runner> runnerClass = (Class<Runner>) Thread.currentThread().getContextClassLoader().loadClass("org.junit.internal.runners.JUnit4ClassRunner"); final Constructor<Runner> constructor = runnerClass.getConstructor(Class.class); return constructor.newInstance(testClass); } catch (Throwable e) { LoggerFactory.getLogger(getClass()).warn("Unable to load JUnit4 runner to calculate Ignored test cases", e); } } return null; }
Example #13
Source File: AllExceptIgnoredTestRunnerBuilder.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public Runner runnerForClass(Class<?> testClass) throws Throwable { try { return new BlockJUnit4ClassRunner(testClass); } catch (Throwable t) { //failed to instantiate BlockJUnitRunner. try deprecated JUnitRunner (for JUnit < 4.5) try { Class<Runner> runnerClass = (Class<Runner>) Thread.currentThread().getContextClassLoader().loadClass("org.junit.internal.runners.JUnit4ClassRunner"); final Constructor<Runner> constructor = runnerClass.getConstructor(Class.class); return constructor.newInstance(testClass); } catch (Throwable e) { LoggerFactory.getLogger(getClass()).warn("Unable to load JUnit4 runner to calculate Ignored test cases", e); } } return null; }
Example #14
Source File: JpaUnitRuleTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified() throws Exception { // GIVEN final JCodeModel jCodeModel = new JCodeModel(); final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest"); final JFieldVar ruleField = jClass.field(JMod.PUBLIC, JpaUnitRule.class, "rule"); ruleField.annotate(Rule.class); final JInvocation instance = JExpr._new(jCodeModel.ref(JpaUnitRule.class)).arg(JExpr.direct("getClass()")); ruleField.init(instance); final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "emf"); final JAnnotationUse jAnnotation = emField.annotate(PersistenceUnit.class); jAnnotation.param("unitName", "test-unit-1"); final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod"); jMethod.annotate(Test.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name()); final BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(cut); final RunListener listener = mock(RunListener.class); final RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); // WHEN runner.run(notifier); // THEN final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class); verify(listener).testStarted(descriptionCaptor.capture()); assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest")); assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod")); verify(listener).testFinished(descriptionCaptor.capture()); assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest")); assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod")); }
Example #15
Source File: JpaUnitRuleTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testClassWithPersistenceContextWithKonfiguredUnitNameSpecified() throws Exception { // GIVEN final JCodeModel jCodeModel = new JCodeModel(); final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest"); final JFieldVar ruleField = jClass.field(JMod.PUBLIC, JpaUnitRule.class, "rule"); ruleField.annotate(Rule.class); final JInvocation instance = JExpr._new(jCodeModel.ref(JpaUnitRule.class)).arg(JExpr.direct("getClass()")); ruleField.init(instance); final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "em"); final JAnnotationUse jAnnotation = emField.annotate(PersistenceContext.class); jAnnotation.param("unitName", "test-unit-1"); final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod"); jMethod.annotate(Test.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name()); final BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(cut); final RunListener listener = mock(RunListener.class); final RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); // WHEN runner.run(notifier); // THEN final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class); verify(listener).testStarted(descriptionCaptor.capture()); assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest")); assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod")); verify(listener).testFinished(descriptionCaptor.capture()); assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest")); assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod")); }
Example #16
Source File: LambdaTestHandler.java From lambda-selenium with MIT License | 5 votes |
public TestResult handleRequest(TestRequest testRequest, Context context) { LoggerContainer.LOGGER = new Logger(context.getLogger()); System.setProperty("target.test.uuid", testRequest.getTestRunUUID()); Optional<Result> result = Optional.empty(); try { BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(getTestClass(testRequest)); runner.filter(new MethodFilter(testRequest.getFrameworkMethod())); result = ofNullable(new JUnitCore().run(runner)); } catch (Exception e) { testResult.setThrowable(e); LOGGER.log(e); } if (result.isPresent()) { testResult.setRunCount(result.get().getRunCount()); testResult.setRunTime(result.get().getRunTime()); LOGGER.log("Run count: " + result.get().getRunCount()); result.get().getFailures().forEach(failure -> { LOGGER.log(failure.getException()); testResult.setThrowable(failure.getException()); }); } return testResult; }
Example #17
Source File: ArkBootRunnerTest.java From sofa-ark with Apache License 2.0 | 5 votes |
@Test public void test() { Assert.assertNotNull(sampleService); Assert.assertNotNull(pluginManagerService); Assert.assertTrue("SampleService".equals(sampleService.say())); ArkBootRunner runner = new ArkBootRunner(ArkBootRunnerTest.class); Field field = ReflectionUtils.findField(ArkBootRunner.class, "runner"); Assert.assertNotNull(field); ReflectionUtils.makeAccessible(field); BlockJUnit4ClassRunner springRunner = (BlockJUnit4ClassRunner) ReflectionUtils.getField( field, runner); Assert.assertTrue(springRunner.getClass().getCanonicalName() .equals(SpringRunner.class.getCanonicalName())); ClassLoader loader = springRunner.getTestClass().getJavaClass().getClassLoader(); Assert.assertTrue(loader.getClass().getCanonicalName() .equals(TestClassLoader.class.getCanonicalName())); Assert.assertEquals(0, TestValueHolder.getTestValue()); eventAdminService.sendEvent(new ArkEvent() { @Override public String getTopic() { return "test-event-A"; } }); Assert.assertEquals(10, TestValueHolder.getTestValue()); eventAdminService.sendEvent(new ArkEvent() { @Override public String getTopic() { return "test-event-B"; } }); Assert.assertEquals(20, TestValueHolder.getTestValue()); }
Example #18
Source File: AllExceptIgnoredTestRunnerBuilder.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public Runner runnerForClass(Class<?> testClass) throws Throwable { try { return new BlockJUnit4ClassRunner(testClass); } catch (Throwable t) { //failed to instantiate BlockJUnitRunner. try deprecated JUnitRunner (for JUnit < 4.5) try { Class<Runner> runnerClass = (Class<Runner>) Thread.currentThread().getContextClassLoader().loadClass("org.junit.internal.runners.JUnit4ClassRunner"); final Constructor<Runner> constructor = runnerClass.getConstructor(Class.class); return constructor.newInstance(testClass); } catch (Throwable e) { LoggerFactory.getLogger(getClass()).warn("Unable to load JUnit4 runner to calculate Ignored test cases", e); } } return null; }
Example #19
Source File: AllExceptIgnoredTestRunnerBuilder.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public Runner runnerForClass(Class<?> testClass) throws Throwable { try { return new BlockJUnit4ClassRunner(testClass); } catch (Throwable t) { //failed to instantiate BlockJUnitRunner. try deprecated JUnitRunner (for JUnit < 4.5) try { Class<Runner> runnerClass = (Class<Runner>) Thread.currentThread().getContextClassLoader().loadClass("org.junit.internal.runners.JUnit4ClassRunner"); final Constructor<Runner> constructor = runnerClass.getConstructor(Class.class); return constructor.newInstance(testClass); } catch (Throwable e) { LoggerFactory.getLogger(getClass()).warn("Unable to load JUnit4 runner to calculate Ignored test cases", e); } } return null; }
Example #20
Source File: TestClassWithDependencyRunner.java From apm-agent-java with Apache License 2.0 | 5 votes |
public TestClassWithDependencyRunner(List<String> dependencies, Class<?> testClass, Class<?>... classesReferencingDependency) throws Exception { List<URL> urls = resolveArtifacts(dependencies); List<Class<?>> classesToExport = new ArrayList<>(); classesToExport.add(testClass); classesToExport.addAll(Arrays.asList(classesReferencingDependency)); urls.add(exportToTempJarFile(classesToExport)); URLClassLoader testClassLoader = new ChildFirstURLClassLoader(urls); testRunner = new BlockJUnit4ClassRunner(testClassLoader.loadClass(testClass.getName())); classLoader = new WeakReference<>(testClassLoader); }
Example #21
Source File: ClassLoaderChangerRunner.java From SimpleFlatMapper with MIT License | 4 votes |
public ClassLoaderChangerRunner(ClassLoader classLoader, BlockJUnit4ClassRunner delegate) { this.delegate = delegate; this.classLoader = classLoader; }
Example #22
Source File: SeparateClassLoaderJUnitRunner.java From waltz with Apache License 2.0 | 4 votes |
private Runner getRunner(Class<?> clazz) throws InitializationError { return new BlockJUnit4ClassRunner(clazz); }
Example #23
Source File: JpaUnitRuleTest.java From jpa-unit with Apache License 2.0 | 4 votes |
@Test public void testClassWithPersistenceContextWithWithOverwrittenConfiguration() throws Exception { // GIVEN final JCodeModel jCodeModel = new JCodeModel(); final JPackage jp = jCodeModel.rootPackage(); final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest"); final JFieldVar ruleField = jClass.field(JMod.PUBLIC, JpaUnitRule.class, "rule"); ruleField.annotate(Rule.class); final JInvocation instance = JExpr._new(jCodeModel.ref(JpaUnitRule.class)).arg(JExpr.direct("getClass()")); ruleField.init(instance); final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "em"); final JAnnotationUse jAnnotation = emField.annotate(PersistenceContext.class); jAnnotation.param("unitName", "test-unit-1"); final JAnnotationArrayMember propArray = jAnnotation.paramArray("properties"); propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.url").param("value", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"); propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.driver").param("value", "org.h2.Driver"); propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.password").param("value", "test"); propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.user").param("value", "test"); final JMethod jMethod = jClass.method(JMod.PUBLIC, jCodeModel.VOID, "testMethod"); jMethod.annotate(Test.class); buildModel(testFolder.getRoot(), jCodeModel); compileModel(testFolder.getRoot()); final Class<?> cut = loadClass(testFolder.getRoot(), jClass.name()); final BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(cut); final RunListener listener = mock(RunListener.class); final RunNotifier notifier = new RunNotifier(); notifier.addListener(listener); // WHEN runner.run(notifier); // THEN final ArgumentCaptor<Description> descriptionCaptor = ArgumentCaptor.forClass(Description.class); verify(listener).testStarted(descriptionCaptor.capture()); assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest")); assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod")); verify(listener).testFinished(descriptionCaptor.capture()); assertThat(descriptionCaptor.getValue().getClassName(), equalTo("ClassUnderTest")); assertThat(descriptionCaptor.getValue().getMethodName(), equalTo("testMethod")); }
Example #24
Source File: JUnitCustomRunnerTestUnitFinderTest.java From pitest with Apache License 2.0 | 4 votes |
@Test public void excludesRunnersWhenRequested() { excludeRunner(BlockJUnit4ClassRunner.class); final Collection<TestUnit> actual = findWithTestee(HasExplicitRunner.class); assertThat(actual).isEmpty(); }
Example #25
Source File: ArgsTest.java From sinavi-jfw with Apache License 2.0 | 4 votes |
@Test public void 静的calledByの深さ指定ミスFalse返却テスト() { boolean called = ArgsCallee.calledByStatic(BlockJUnit4ClassRunner.class, 1); assertFalse(called); }
Example #26
Source File: ArgsTest.java From sinavi-jfw with Apache License 2.0 | 4 votes |
@Test public void 動的calledByの深さ指定ミスFalse返却テスト() { boolean called = new ArgsCallee().calledByVirtual(BlockJUnit4ClassRunner.class, 1); assertFalse(called); }
Example #27
Source File: ParameterizedCucumber.java From senbot with MIT License | 4 votes |
/** * Constructor looping though the {@link Parameterized} {@link Runner}'s and * adding the {@link CucumberFeature}'s found as children to each one * ensuring the {@link TestEnvironment} is available for each {@link Runner} * . * * @param klass * @throws Throwable */ public ParameterizedCucumber(Class<?> klass) throws Throwable { super(klass); log.debug("Initializing the ParameterizedCucumber runner"); final ClassLoader classLoader = klass.getClassLoader(); Assertions.assertNoCucumberAnnotatedMethods(klass); // Class<? extends Annotation>[] annotationClasses = new Class[]{CucumberOptions.class, Options.class}; // RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(klass, annotationClasses); RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(klass); final RuntimeOptions runtimeOptions = runtimeOptionsFactory.create(); ResourceLoader resourceLoader = new MultiLoader(classLoader); // ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader); // runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions); runtime = new Runtime(resourceLoader, classLoader, runtimeOptions); final ThreadAwareFormatter threadAwareWrappedFormatter = new ThreadAwareFormatter(runtimeOptions, classLoader); Reporter threadAwareReporter = new ThreadAwareReporter(threadAwareWrappedFormatter, classLoader, runtimeOptions); runtimeOptions.formatters.clear(); runtimeOptions.formatters.add(threadAwareWrappedFormatter); jUnitReporter = new JUnitReporter(threadAwareReporter, threadAwareWrappedFormatter, runtimeOptions.strict); //overwrite the reporter so we can alter the path to write to List<CucumberFeature> cucumberFeatures = runtimeOptions.cucumberFeatures(resourceLoader); List<Runner> parameterizedChildren = super.getChildren(); final SeleniumManager seleniumManager = SenBotContext.getSenBotContext().getSeleniumManager(); final CucumberManager cucumberManager = SenBotContext.getSenBotContext().getCucumberManager(); for (int i = 0; i < parameterizedChildren.size(); i++) { BlockJUnit4ClassRunner paramRunner = (BlockJUnit4ClassRunner) parameterizedChildren.get(i); final TestEnvironment environment = seleniumManager.getSeleniumTestEnvironments().get(i); log.debug("Load runners for test envrironment: " + environment.toString()); for (final CucumberFeature cucumberFeature : cucumberFeatures) { Feature originalFeature = cucumberFeature.getGherkinFeature(); log.debug("Load runner for test cucumberFeature: " + originalFeature.getDescription() + " on evironment " + environment.toString()); ThreadPoolFeatureRunnerScheduler environmentFeatureRunner = new ThreadPoolFeatureRunnerScheduler(environment, cucumberFeature, runtime, jUnitReporter, cucumberManager.getFeatureFileTimeout()); setScheduler(environmentFeatureRunner); children.add(environmentFeatureRunner); } } }