當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。