本文整理汇总了Java中org.junit.runners.JUnit4类的典型用法代码示例。如果您正苦于以下问题:Java JUnit4类的具体用法?Java JUnit4怎么用?Java JUnit4使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JUnit4类属于org.junit.runners包,在下文中一共展示了JUnit4类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isJUnit4TestClass
import org.junit.runners.JUnit4; //导入依赖的package包/类
/**
* @return true if {@param cls} is {@link JUnit4} annotated.
*/
protected boolean isJUnit4TestClass(Class cls) {
// Need to find test classes, otherwise crashes with b/11790448.
if (!cls.getName().endsWith("Test")) {
return false;
}
// Check the annotations.
Annotation annotation = cls.getAnnotation(RunWith.class);
if (annotation != null) {
RunWith runWith = (RunWith) annotation;
Object value = runWith.value();
if (value.equals(JUnit4.class) || value.equals(Suite.class)) {
return true;
}
}
return false;
}
示例2: test_launch_java_process
import org.junit.runners.JUnit4; //导入依赖的package包/类
@Test
public void test_launch_java_process() throws InterruptedException {
JavaProcess proc = JavaProcess.newBuilder()
.mainClass(Echo.class.getName())
.addClasspath(Echo.class)
.addClasspath(JUnit4.class)
.arguments("one", "two")
.addJvmProp("my.prop", "world")
.addJvmArg("-Xmx512m")
.env("VAR", "Hello")
.pipeStdout()
.pipeStderr()
.recordStdout()
.recordStderr()
.build();
System.out.println(proc.getCommand());
assertEquals(0, proc.waitFor());
assertEquals("Hello\n" +
"world\n" +
"one\n" +
"two\n", proc.getRecordedStdoutText());
assertEquals("", proc.getRecordedStderrText());
}
示例3: test_launch_failing_java_process
import org.junit.runners.JUnit4; //导入依赖的package包/类
@Test
public void test_launch_failing_java_process() throws InterruptedException {
JavaProcess proc = JavaProcess.newBuilder()
.mainClass(EchoFail.class.getName())
.addClasspath(EchoFail.class)
.addClasspath(JUnit4.class)
.arguments("one", "two")
.addJvmProp("my.prop", "world")
.addJvmArg("-Xmx512m")
.env("VAR", "Hello")
.recordStdout()
.recordStderr()
.build();
System.out.println(proc.getCommand());
assertEquals(1, proc.waitFor());
assertEquals("Hello\n" +
"world\n" +
"one\n" +
"two\n", proc.getRecordedStdoutText());
assertTrue(proc.getRecordedStderrText().contains("Exception in thread \"main\" java.lang.AssertionError: message"));
}
示例4: isJUnit4TestClass
import org.junit.runners.JUnit4; //导入依赖的package包/类
/**
* @return true if {@param cls} is {@link JUnit4} annotated.
*/
protected boolean isJUnit4TestClass(Class cls) {
// Need to find test classes, otherwise crashes with b/11790448.
if (!cls.getName().endsWith("Test")) {
return false;
}
// Check the annotations.
Annotation annotation = cls.getAnnotation(RunWith.class);
if (annotation != null) {
RunWith runWith = (RunWith) annotation;
if (runWith.value().equals(JUnit4.class)) {
return true;
}
}
return false;
}
示例5: noBeforeOnClasspath
import org.junit.runners.JUnit4; //导入依赖的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();
}
示例6: findJUnitTests
import org.junit.runners.JUnit4; //导入依赖的package包/类
public List<String> findJUnitTests(TestSuite testSuite)
{
List<String> junitTests = new ArrayList<String>();
try {
Class<?>[] clazzez = getUnitTestClasses(testSuite);
if (clazzez != null && clazzez.length > 0) {
for (Class<?> clazz : clazzez) {
//From https://github.com/KentBeck/junit/blob/master/src/main/java/org/junit/runners/BlockJUnit4ClassRunner.java method computeTestMethods
try {
List<FrameworkMethod> methods = new JUnit4(clazz).getTestClass().getAnnotatedMethods(Test.class);
if (methods != null && !methods.isEmpty())
for (FrameworkMethod method: methods)
junitTests.add(clazz.getName() + "/" + method.getName());
}
catch(InitializationError e2) {
StringBuilder errors = new StringBuilder();
for(Throwable cause : e2.getCauses())
errors.append("\n").append(cause.getMessage());
LOG.error("Failed to recognize class '" + clazz + "' as unitTestClass: " + errors.toString());
}
}
}
}
catch(Exception e) {
LOG.error(CLOUD_SECURITY_ERROR + e.getMessage(), e);
}
return junitTests;
}
示例7: getDelegateRunningToOn
import org.junit.runners.JUnit4; //导入依赖的package包/类
public Class<? extends Runner> getDelegateRunningToOn(Class<?> testClass)
{
Class<? extends Runner> runnerClass = JUnit4.class;
DelegateRunningTo annotation = testClass.getAnnotation(DelegateRunningTo.class);
if(annotation != null)
{
runnerClass = annotation.value();
}
return runnerClass;
}
示例8: annotatedClassWithoutValueReturnsDefault
import org.junit.runners.JUnit4; //导入依赖的package包/类
@Test
public void annotatedClassWithoutValueReturnsDefault()
{
DelegateRunningToDiscoverer discoverer = new DelegateRunningToDiscoverer();
Class discovered = discoverer.getDelegateRunningToOn(FixtureWithoutValue.class);
assertThat(discovered, equalTo((Class) JUnit4.class));
}
示例9: unannotatedClassReturnsDefault
import org.junit.runners.JUnit4; //导入依赖的package包/类
@Test
public void unannotatedClassReturnsDefault()
{
DelegateRunningToDiscoverer discoverer = new DelegateRunningToDiscoverer();
Class discovered = discoverer.getDelegateRunningToOn(UnannotatedFixture.class);
assertThat(discovered, equalTo((Class) JUnit4.class));
}
示例10: executeJunitTest
import org.junit.runners.JUnit4; //导入依赖的package包/类
private void executeJunitTest(final Class<?> testClass) {
try {
new JUnit4(testClass).run(runNotifierWith(runListeners));
} catch (final InitializationError initializationError) {
throw new RuntimeException(initializationError);
}
}
示例11: getRunnerClass
import org.junit.runners.JUnit4; //导入依赖的package包/类
@Override
protected Class<? extends Runner> getRunnerClass() {
return JUnit4.class;
}
示例12: JicUnitRunner
import org.junit.runners.JUnit4; //导入依赖的package包/类
public JicUnitRunner(Class<?> testClass) throws Throwable {
Class<? extends Runner> runnerClass;
RunInContainerWith runInContainerWith = findAnnotation(testClass, RunInContainerWith.class);
// figure out if this is happening locally or in the JEE container
String containerUrl = getContainerUrl();
if (containerUrl == null) {
// this code is executed in the JEE container
if (runInContainerWith != null) {
runnerClass = runInContainerWith.value();
} else {
runnerClass = JUnit4.class;
}
try {
Constructor<? extends Runner> constructor = runnerClass
.getDeclaredConstructor(Class.class);
mRunner = constructor.newInstance(testClass);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
Throwable cause = (e.getCause() != null ? e.getCause() : e);
String msg = "Unable to create instance of " + runnerClass + " using test class " + testClass.getName() + " Reason: " + cause;
if (cause instanceof InitializationError) {
InitializationError initializationError = (InitializationError) cause;
msg = msg + " " + initializationError.getCauses();
}
sLog.log(Level.SEVERE, msg);
throw new RuntimeException(msg, cause);
}
} else {
// this code is executed locally so create a ProxyRunner which will
// forward the execution to the container
if (runInContainerWith != null) {
runnerClass = runInContainerWith.value();
if (Parameterized.class.isAssignableFrom(runnerClass)) {
mRunner = new ParameterizedProxyRunner(testClass, containerUrl);
} else if (Suite.class.isAssignableFrom(runnerClass)) {
throw new IllegalArgumentException(
RunInContainerWith.class.getSimpleName()
+ " annotation does not support Suite runner or any subclass of Suite except Parameterized");
} else {
Runner runInContainerRunner = runnerClass.getDeclaredConstructor(Class.class)
.newInstance(testClass);
Description desc = runInContainerRunner.getDescription();
mRunner = new BasicProxyRunner(testClass, containerUrl, desc);
}
} else {
mRunner = new BasicProxyRunner(testClass, containerUrl);
}
}
}
示例13: shouldIgnoreJUnitClasses
import org.junit.runners.JUnit4; //导入依赖的package包/类
@Test
public void shouldIgnoreJUnitClasses() {
assertIgnored(JUnit4.class);
}
示例14: runTest
import org.junit.runners.JUnit4; //导入依赖的package包/类
private static void runTest(RunNotifier notifier, Class<?> klass) throws InitializationError {
JUnit4 runner = new JUnit4(klass);
runner.run(notifier);
}