本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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"));
}
示例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();
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
};
}
示例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;
}
示例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);
}
});
}
示例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());
}
}
示例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);
}