当前位置: 首页>>代码示例>>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;未经允许,请勿转载。