當前位置: 首頁>>代碼示例>>Java>>正文


Java BlockJUnit4ClassRunner類代碼示例

本文整理匯總了Java中org.junit.runners.BlockJUnit4ClassRunner的典型用法代碼示例。如果您正苦於以下問題:Java BlockJUnit4ClassRunner類的具體用法?Java BlockJUnit4ClassRunner怎麽用?Java BlockJUnit4ClassRunner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BlockJUnit4ClassRunner類屬於org.junit.runners包,在下文中一共展示了BlockJUnit4ClassRunner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: runnerForClass

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
@Override
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;
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:17,代碼來源:AllExceptIgnoredTestRunnerBuilder.java

示例2: getTestRequests

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
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;
}
 
開發者ID:blackboard,項目名稱:lambda-selenium,代碼行數:19,代碼來源:LambdaTestSuite.java

示例3: runTest

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
public TestResults runTest(final Class<?> testClazz, final String methodName)
    throws InitializationError {
  BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(testClazz) {
    @Override
    protected List<FrameworkMethod> computeTestMethods() {
      try {
        Method method = testClazz.getMethod(methodName);
        return Arrays.asList(new FrameworkMethod(method));

      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
  };
  TestResults res = new TestResults(logger, server, playerName);
  runner.run(res);
  return res;
}
 
開發者ID:wizards-of-lua,項目名稱:wizards-of-lua,代碼行數:19,代碼來源:TestMethodExecutor.java

示例4: testClassWithPersistenceContextWithKonfiguredUnitNameSpecified

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
@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"));
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:40,代碼來源:JpaUnitRuleTest.java

示例5: describeChildCreatesDescriptionForWithTestUserTest

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
@Test
public void describeChildCreatesDescriptionForWithTestUserTest() throws Exception {
    SpringSecurityJUnit4ClassRunner runner = new SpringSecurityJUnit4ClassRunner(MockWithMockUserTest.class);

    Method method2Test = MockWithMockUserTest.class.getMethod("testWithWithMockUser");
    FrameworkMethod method = new AnnotationFrameworkMethod(new FrameworkMethod(method2Test), method2Test.getDeclaredAnnotation(WithMockUser.class));
    Description actualDescription = runner.describeChild(method);

    BlockJUnit4ClassRunner expectedRunner = new BlockJUnit4ClassRunner(MockWithMockUserTest.class);
    Method method1 = BlockJUnit4ClassRunner.class.getDeclaredMethod("describeChild", FrameworkMethod.class);
    method1.setAccessible(true);
    Description expectedDescription = (Description) method1.invoke(expectedRunner, method);

    assertDescriptionDetailsEqual(expectedDescription, actualDescription);
    assertEquals(expectedDescription.getChildren().size(), actualDescription.getChildren().size());
}
 
開發者ID:Mastercard,項目名稱:java8-spring-security-test,代碼行數:17,代碼來源:SpringSecurityJUnit4ClassRunnerTests.java

示例6: validateAllMethods

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
private List<Throwable> validateAllMethods(Class<?> clazz) {
    try {
        new BlockJUnit4ClassRunner(clazz);
    } catch (InitializationError e) {
        return e.getCauses();
    }
    return Collections.emptyList();
}
 
開發者ID:DIVERSIFY-project,項目名稱:sosiefier,代碼行數:9,代碼來源:TestMethodTest.java

示例7: useChildHarvester

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
@Test
public void useChildHarvester() throws InitializationError {
    log = "";
    ParentRunner<?> runner = new BlockJUnit4ClassRunner(FruitTest.class);
    runner.setScheduler(new RunnerScheduler() {
        public void schedule(Runnable childStatement) {
            log += "before ";
            childStatement.run();
            log += "after ";
        }

        public void finished() {
            log += "afterAll ";
        }
    });

    runner.run(new RunNotifier());
    assertEquals("before apple after before banana after afterAll ", log);
}
 
開發者ID:DIVERSIFY-project,項目名稱:sosiefier,代碼行數:20,代碼來源:ParentRunnerTest.java

示例8: noBeforeOnClasspath

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
@Test
public void noBeforeOnClasspath() throws Exception {
  File libJar = tempFolder.newFile("lib.jar");
  try (FileOutputStream fis = new FileOutputStream(libJar);
      JarOutputStream jos = new JarOutputStream(fis)) {
    addClassToJar(jos, RunWith.class);
    addClassToJar(jos, JUnit4.class);
    addClassToJar(jos, BlockJUnit4ClassRunner.class);
    addClassToJar(jos, ParentRunner.class);
    addClassToJar(jos, SuperTest.class);
    addClassToJar(jos, SuperTest.class.getEnclosingClass());
  }
  compilationHelper
      .addSourceLines(
          "Test.java",
          "import org.junit.runner.RunWith;",
          "import org.junit.runners.JUnit4;",
          "import " + SuperTest.class.getCanonicalName() + ";",
          "@RunWith(JUnit4.class)",
          "class Test extends SuperTest {",
          "  @Override public void setUp() {}",
          "}")
      .setArgs(Arrays.asList("-cp", libJar.toString()))
      .doTest();
}
 
開發者ID:google,項目名稱:error-prone,代碼行數:26,代碼來源:JUnit4SetUpNotRunTest.java

示例9: getChildren

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
@Override
protected List<Runner> getChildren() {
  // one runner for each parameter
  List<Runner> runners = super.getChildren();
  List<Runner> proxyRunners = new ArrayList<>(runners.size());
  for (Runner runner : runners) {
    // if the next line fails then the internal of Parameterized.class has been updated since this works with JUnit 4.11
    BlockJUnit4ClassRunner blockJUnit4ClassRunner = (BlockJUnit4ClassRunner) runner;
    Description description = blockJUnit4ClassRunner.getDescription();
    String name = description.getDisplayName();
    try {
      proxyRunners
          .add(new ProxyTestClassRunnerForParameters(mTestClass, mContainerUrl, name));
    } catch (InitializationError e) {
      throw new RuntimeException("Could not create runner for paramamter " + name, e);
    }
  }
  return proxyRunners;
}
 
開發者ID:Lucas3oo,項目名稱:jicunit,代碼行數:20,代碼來源:ParameterizedProxyRunner.java

示例10: getChildren

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
protected List getChildren() {
  final List children = super.getChildren();
  for (int i = 0; i < children.size(); i++) {
    try {
      final BlockJUnit4ClassRunner child = (BlockJUnit4ClassRunner)children.get(i);
      final Method getChildrenMethod = BlockJUnit4ClassRunner.class.getDeclaredMethod("getChildren", new Class[0]);
      getChildrenMethod.setAccessible(true);
      final List list = (List)getChildrenMethod.invoke(child, new Object[0]);
      for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
        final FrameworkMethod description = (FrameworkMethod)iterator.next();
        if (!description.getName().equals(myMethodName)) {
          iterator.remove();
        }
      }
    }
    catch (Exception e) {
     e.printStackTrace();
    }
  }
  return children;
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:22,代碼來源:JUnit4TestRunnerUtil.java

示例11: EjbWithMockitoRunner

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
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;
        }

    };

}
 
開發者ID:michaelyaakoby,項目名稱:testfun,代碼行數:26,代碼來源:EjbWithMockitoRunner.java

示例12: handleRequest

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
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;
}
 
開發者ID:blackboard,項目名稱:lambda-selenium,代碼行數:28,代碼來源:LambdaTestHandler.java

示例13: createSuite

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
private void createSuite(Class<?> suiteClass) throws Exception {
	suite = new XTFTestSuite(suiteClass, new RunnerBuilder() {
		@Override
		public Runner runnerForClass(Class<?> testClass) throws Throwable {
			return new BlockJUnit4ClassRunner(testClass);
		}
	});
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:9,代碼來源:XTFTestSuiteTest.java

示例14: runChildBefore

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
static void runChildBefore(final BlockJUnit4ClassRunner runner, final FrameworkMethod method,
		final RunNotifier notifier) {
	final StroomExpectedException stroomExpectedException = method.getAnnotation(StroomExpectedException.class);
	if (stroomExpectedException != null) {
		StroomJunitConsoleAppender.setExpectedException(stroomExpectedException.exception());
		LOGGER.info(">>> %s.  Expecting Exceptions %s", method.getMethod(), stroomExpectedException.exception());
	} else {
		LOGGER.info(">>> %s", method.getMethod());
	}

}
 
開發者ID:gchq,項目名稱:stroom-agent,代碼行數:12,代碼來源:StroomJUnit4ClassRunner.java

示例15: runChildAfter

import org.junit.runners.BlockJUnit4ClassRunner; //導入依賴的package包/類
static void runChildAfter(final BlockJUnit4ClassRunner runner, final FrameworkMethod method,
		final RunNotifier notifier, final LogExecutionTime logExecutionTime) {
	LOGGER.info("<<< %s took %s", method.getMethod(), logExecutionTime);
	if (StroomJunitConsoleAppender.getUnexpectedExceptions().size() > 0) {
		notifier.fireTestFailure(new Failure(
				Description.createTestDescription(runner.getTestClass().getJavaClass(), method.getName()),
				StroomJunitConsoleAppender.getUnexpectedExceptions().get(0)));
	}
	StroomJunitConsoleAppender.setExpectedException(null);
}
 
開發者ID:gchq,項目名稱:stroom-agent,代碼行數:11,代碼來源:StroomJUnit4ClassRunner.java


注:本文中的org.junit.runners.BlockJUnit4ClassRunner類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。