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


Java RunNotifier.addListener方法代碼示例

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


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

示例1: run

import org.junit.runner.notification.RunNotifier; //導入方法依賴的package包/類
final void run(final RunNotifier notifier) {
    RunNotifier nested = new RunNotifier();
    NestedRunListener nestedListener = new NestedRunListener(notifier);
    nested.addListener(nestedListener);

    try {
        runEnabledTests(nested);
    } finally {
        nestedListener.cleanup();
    }

    for (Description disabledTest : disabledTests) {
        nested.fireTestStarted(disabledTest);
        nested.fireTestIgnored(disabledTest);
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:17,代碼來源:AbstractMultiTestRunner.java

示例2: executeTestClass

import org.junit.runner.notification.RunNotifier; //導入方法依賴的package包/類
private static void executeTestClass(Class<?> testClass) throws Throwable {

        Throwable[] throwables = new Throwable[1];
        WebTesterJUnitRunner runner = new WebTesterJUnitRunner(testClass);
        RunNotifier notifier = new RunNotifier();
        notifier.addListener(new RunListener() {

            public void testFailure(Failure failure) throws Exception {
                System.out.println("testFailure");
                throwables[0] = failure.getException();
            }

        });
        runner.run(notifier);

        if (throwables[0] != null) {
            throw throwables[0];
        }

    }
 
開發者ID:testIT-WebTester,項目名稱:webtester2-core,代碼行數:21,代碼來源:WebTesterJUnitRunnerTest.java

示例3: testClassWithPersistenceContextWithKonfiguredUnitNameSpecified

import org.junit.runner.notification.RunNotifier; //導入方法依賴的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

示例4: addListener

import org.junit.runner.notification.RunNotifier; //導入方法依賴的package包/類
@After("execution(org.junit.runner.notification.RunNotifier.new())")
public void addListener(final JoinPoint point) {
    final RunNotifier notifier = (RunNotifier) point.getThis();
    notifier.removeListener(allure);
    notifier.addListener(allure);
}
 
開發者ID:allure-framework,項目名稱:allure-java,代碼行數:7,代碼來源:AllureJunit4ListenerAspect.java

示例5: run

import org.junit.runner.notification.RunNotifier; //導入方法依賴的package包/類
@Override
public void run(RunNotifier notifier) {
	// To avoid duplicates need to do N-1 times if there's N levels of these suites
	// Note, in this notifier implementation it does not matter if we try to remove
	// a listener if is not contained with the notifier
	notifier.removeListener(listener);

	notifier.addListener(listener);
	super.run(notifier);
	notifier.removeListener(listener);
}
 
開發者ID:eclipse,項目名稱:january,代碼行數:12,代碼來源:TestUtils.java

示例6: testClassWithPersistenceContextWithoutUnitNameSpecified

import org.junit.runner.notification.RunNotifier; //導入方法依賴的package包/類
@Test
public void testClassWithPersistenceContextWithoutUnitNameSpecified() throws Exception {
    // GIVEN
    final JCodeModel jCodeModel = new JCodeModel();
    final JPackage jp = jCodeModel.rootPackage();
    final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
    final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class);
    jAnnotationUse.param("value", JpaUnitRunner.class);
    final JFieldVar emField = jClass.field(JMod.PRIVATE, EntityManager.class, "em");
    emField.annotate(PersistenceContext.class);
    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 RunListener listener = mock(RunListener.class);
    final RunNotifier notifier = new RunNotifier();
    notifier.addListener(listener);

    final JpaUnitRunner runner = new JpaUnitRunner(cut);

    // WHEN
    runner.run(notifier);

    // THEN
    final ArgumentCaptor<Failure> failureCaptor = ArgumentCaptor.forClass(Failure.class);
    verify(listener).testFailure(failureCaptor.capture());

    final Failure failure = failureCaptor.getValue();
    assertThat(failure.getException().getClass(), equalTo(JpaUnitException.class));
    assertThat(failure.getException().getMessage(), containsString("No Persistence"));
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:36,代碼來源:JpaUnitRunnerTest.java

示例7: run

import org.junit.runner.notification.RunNotifier; //導入方法依賴的package包/類
@Override
public void run(RunNotifier notifier) {
  if (isItFailedTestsRerun && !canRerunFailedTests()) {
    shutdownRerun(notifier);
  } else {
    if (storeFailedResults) {
      notifier.addListener(new BobcumberListener(this));
    }
    super.run(notifier);
    closeWebDriverPool();
  }
}
 
開發者ID:Cognifide,項目名稱:bobcat,代碼行數:13,代碼來源:Bobcumber.java

示例8: executeTestMethod

import org.junit.runner.notification.RunNotifier; //導入方法依賴的package包/類
/**
 * This method allows access to the test invocation, from within the modules (who get a reference to the runner
 * via the context). We do not check for listeners veto's (typically, these modules will veto the execution of
 * the test in normal execution mode, and call this method later on to do their logic).
 * 
 * @param testObject
 * @param method 
 */
public void executeTestMethod(Object testObject, Method method) {
    TestMethod testMethod = wrapMethod(method);        
    RunNotifier notifier = new RunNotifier();
    InterceptingListener listener = new InterceptingListener();
    notifier.addListener(listener);
    Description description = methodDescription(method);
    createMethodRoadie(testObject, method, testMethod, notifier, description).run();
    if(listener.isFailed()) {
        StringBuilder msg = new StringBuilder("Exeception while executing ");
        msg.append(method.getName()).append(": ").append(listener.getFailure().getDescription());
        throw new UnitilsException(msg.toString(),listener.getFailure().getException());
    }
}
 
開發者ID:linux-china,項目名稱:unitils,代碼行數:22,代碼來源:UnitilsJUnit4TestClassRunner.java

示例9: main

import org.junit.runner.notification.RunNotifier; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    Result result = new Result();
    RunNotifier runNotifier = new RunNotifier();
    runNotifier.addListener(result.createListener());

    JUnit4ClassRunner classRunner = new JUnit4ClassRunner(UnitilsIntegrationTest.class);
    classRunner.run(runNotifier);
    if (result.getFailureCount() > 0) {
        registerFailure();
    }
}
 
開發者ID:linux-china,項目名稱:unitils,代碼行數:12,代碼來源:UnitilsIntegrationTest.java

示例10: runTests

import org.junit.runner.notification.RunNotifier; //導入方法依賴的package包/類
public void runTests(Class<?>... testClasses) throws Exception {
	result = new Result();
       RunNotifier runNotifier = new RunNotifier();
       runNotifier.addListener(result.createListener());
       
       for (Class<?> testClass : testClasses) {
       	UnitilsJUnit4TestClassRunner testClassRunner = new TestUnitilsJUnit4TestClassRunner(testClass);
       	testClassRunner.run(runNotifier);
       }
}
 
開發者ID:linux-china,項目名稱:unitils,代碼行數:11,代碼來源:JUnit4TestExecutor.java

示例11: testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified

import org.junit.runner.notification.RunNotifier; //導入方法依賴的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

示例12: testClassWithPersistenceContextWithKonfiguredUnitNameSpecified

import org.junit.runner.notification.RunNotifier; //導入方法依賴的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 JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class);
    jAnnotationUse.param("value", JpaUnitRunner.class);
    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 JpaUnitRunner runner = new JpaUnitRunner(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,代碼行數:38,代碼來源:JpaUnitRunnerTest.java

示例13: run

import org.junit.runner.notification.RunNotifier; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public void run(final RunNotifier notifier) {
  try {
    notifier.removeListener(testRunRecording); // remove existing listeners that could be added by suite or class runners
    notifier.addListener(testRunRecording);
    super.run(notifier);
  } finally {
    notifier.removeListener(testRunRecording);
  }
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:12,代碼來源:SwtBotRecordingTestRunner.java

示例14: testClassWithPersistenceUnitWithKonfiguredUnitNameSpecified

import org.junit.runner.notification.RunNotifier; //導入方法依賴的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 JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class);
    jAnnotationUse.param("value", JpaUnitRunner.class);
    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 JpaUnitRunner runner = new JpaUnitRunner(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,代碼行數:38,代碼來源:JpaUnitRunnerTest.java

示例15: testClassWithPersistenceContextAndPersistenceUnitFields

import org.junit.runner.notification.RunNotifier; //導入方法依賴的package包/類
@Test
public void testClassWithPersistenceContextAndPersistenceUnitFields() throws Exception {
    // GIVEN
    final JCodeModel jCodeModel = new JCodeModel();
    final JPackage jp = jCodeModel.rootPackage();
    final JDefinedClass jClass = jp._class(JMod.PUBLIC, "ClassUnderTest");
    final JAnnotationUse jAnnotationUse = jClass.annotate(RunWith.class);
    jAnnotationUse.param("value", JpaUnitRunner.class);
    final JFieldVar emf1Field = jClass.field(JMod.PRIVATE, EntityManager.class, "em");
    emf1Field.annotate(PersistenceContext.class);
    final JFieldVar emf2Field = jClass.field(JMod.PRIVATE, EntityManagerFactory.class, "emf");
    emf2Field.annotate(PersistenceUnit.class);
    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 RunListener listener = mock(RunListener.class);
    final RunNotifier notifier = new RunNotifier();
    notifier.addListener(listener);

    final JpaUnitRunner runner = new JpaUnitRunner(cut);

    // WHEN
    runner.run(notifier);

    // THEN
    final ArgumentCaptor<Failure> failureCaptor = ArgumentCaptor.forClass(Failure.class);
    verify(listener).testFailure(failureCaptor.capture());

    final Failure failure = failureCaptor.getValue();
    assertThat(failure.getException().getClass(), equalTo(IllegalArgumentException.class));
    assertThat(failure.getException().getMessage(), containsString("either @PersistenceUnit or @PersistenceContext"));
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:38,代碼來源:JpaUnitRunnerTest.java


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