当前位置: 首页>>代码示例>>Java>>正文


Java JUnit4类代码示例

本文整理汇总了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;
}
 
开发者ID:doppllib,项目名称:core-doppl,代码行数:20,代码来源:DopplJunitTestHelper.java

示例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());
}
 
开发者ID:Terracotta-OSS,项目名称:ipc-eventbus,代码行数:25,代码来源:JavaProcessTest.java

示例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"));
}
 
开发者ID:Terracotta-OSS,项目名称:ipc-eventbus,代码行数:23,代码来源:JavaProcessTest.java

示例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;
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:19,代码来源:JUnitTestRunner.java

示例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();
}
 
开发者ID:google,项目名称:error-prone,代码行数:26,代码来源:JUnit4SetUpNotRunTest.java

示例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;
}
 
开发者ID:appronto,项目名称:RedisConnector,代码行数:34,代码来源:TestManager.java

示例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;
}
 
开发者ID:BinaryTweed,项目名称:quarantining-test-runner,代码行数:13,代码来源:DelegateRunningToDiscoverer.java

示例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));
}
 
开发者ID:BinaryTweed,项目名称:quarantining-test-runner,代码行数:8,代码来源:DelegateRunningToDiscovererTest.java

示例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));
}
 
开发者ID:BinaryTweed,项目名称:quarantining-test-runner,代码行数:8,代码来源:DelegateRunningToDiscovererTest.java

示例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);
    }
}
 
开发者ID:fyodor-org-uk,项目名称:fyodor,代码行数:8,代码来源:TestRunner.java

示例11: getRunnerClass

import org.junit.runners.JUnit4; //导入依赖的package包/类
@Override
protected Class<? extends Runner> getRunnerClass() {
	return JUnit4.class;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:5,代码来源:RepeatedSpringRuleTests.java

示例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);
    }
  }

}
 
开发者ID:Lucas3oo,项目名称:jicunit,代码行数:51,代码来源:JicUnitRunner.java

示例13: shouldIgnoreJUnitClasses

import org.junit.runners.JUnit4; //导入依赖的package包/类
@Test
public void shouldIgnoreJUnitClasses() {
  assertIgnored(JUnit4.class);
}
 
开发者ID:hcoles,项目名称:pitest,代码行数:5,代码来源:IgnoreCoreClassesTest.java

示例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);
}
 
开发者ID:chaquotay,项目名称:whiskers,代码行数:5,代码来源:Main.java


注:本文中的org.junit.runners.JUnit4类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。