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


Java BlockJUnit4ClassRunner.run方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified

import org.junit.runners.BlockJUnit4ClassRunner; //導入方法依賴的package包/類
@Test
public void testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified() 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, EntityManagerFactory.class, "emf");
    final JAnnotationUse jAnnotation = emField.annotate(PersistenceUnit.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

示例4: runTests

import org.junit.runners.BlockJUnit4ClassRunner; //導入方法依賴的package包/類
public TestResults runTests(final Class<?> testClazz) throws InitializationError {
  BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(testClazz);
  TestResults res = new TestResults(logger, server, playerName);
  runner.run(res);
  return res;
}
 
開發者ID:wizards-of-lua,項目名稱:wizards-of-lua,代碼行數:7,代碼來源:TestClassExecutor.java

示例5: testClassWithPersistenceContextWithWithOverwrittenConfiguration

import org.junit.runners.BlockJUnit4ClassRunner; //導入方法依賴的package包/類
@Test
public void testClassWithPersistenceContextWithWithOverwrittenConfiguration() 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 JAnnotationArrayMember propArray = jAnnotation.paramArray("properties");
    propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.url").param("value",
            "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.driver").param("value", "org.h2.Driver");
    propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.password").param("value", "test");
    propArray.annotate(PersistenceProperty.class).param("name", "javax.persistence.jdbc.user").param("value", "test");
    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,代碼行數:46,代碼來源:JpaUnitRuleTest.java

示例6: runPlainTestClass

import org.junit.runners.BlockJUnit4ClassRunner; //導入方法依賴的package包/類
private void runPlainTestClass(Class<?> testClass) throws Exception {
BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(testClass);
RunNotifier notifier = new RunNotifier();
notifier.addListener(new MyListener());
runner.run(notifier);
   }
 
開發者ID:lucaspouzac,項目名稱:contiperf,代碼行數:7,代碼來源:AbstractContiPerfTest.java


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