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


Java RunListener类代码示例

本文整理汇总了Java中org.junit.runner.notification.RunListener的典型用法代码示例。如果您正苦于以下问题:Java RunListener类的具体用法?Java RunListener怎么用?Java RunListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RunListener类属于org.junit.runner.notification包,在下文中一共展示了RunListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeTestClass

import org.junit.runner.notification.RunListener; //导入依赖的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

示例2: testClassWithPersistenceContextWithKonfiguredUnitNameSpecified

import org.junit.runner.notification.RunListener; //导入依赖的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: run

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
public static TestListener run(InputConfiguration configuration,
							   URLClassLoader classLoader,
							   CtType<?> testClass,
							   Collection<String> testMethodNames,
                                  RunListener... listeners) {
	Logger.reset();
	Logger.setLogDir(new File(configuration.getInputProgram().getProgramDir() + "/log"));
	if (testClass.getModifiers().contains(ModifierKind.ABSTRACT)) {
		final CtTypeReference<?> referenceToAbstractClass = testClass.getReference();
		return testClass.getFactory().Class().getAll().stream()
				.filter(ctType -> ctType.getSuperclass() != null)
				.filter(ctType ->
						ctType.getSuperclass().equals(referenceToAbstractClass)
				)
				.map(ctType -> run(configuration, classLoader, ctType, testMethodNames, listeners))
				.reduce(new TestListener(), TestListener::aggregate);
	}
	return TestRunnerFactory.createRunner(testClass, classLoader).run(testClass.getQualifiedName(), testMethodNames, listeners);
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:20,代码来源:TestLauncher.java

示例4: run

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
@Override
public TestListener run(Class<?> testClass, Collection<String> testMethodNames, RunListener... additionalListeners) {
    if (additionalListeners.length != 0) {
        LOGGER.warn("Additional listeners is not supported for ReflectiveTestRunner");
    }
    ExecutorService executor = Executors.newSingleThreadExecutor();
    final Future<?> submit = executor.submit(() -> {
        Thread.currentThread().setContextClassLoader(classLoader);
        return runUsingReflection(testClass);
    });
    try {
        Object listener = submit.get(10000000 * (testMethodNames.size() + 1),
                TimeUnit.MILLISECONDS);
        return TestListener.copyFromObject(listener, testMethodNames);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        submit.cancel(true);
        executor.shutdownNow();
        Logger.stopLogging();
        Logger.close();
    }
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:24,代码来源:ReflectiveTestRunner.java

示例5: simpleValidTestMocked

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
@Test
public void simpleValidTestMocked() throws Exception {

    RunListener listener = runTestWithMockListener(ValidTest.class);

    ArgumentCaptor<Description> argument = ArgumentCaptor.forClass(Description.class);

    verify(listener, times(1)).testRunStarted(Mockito.any());
    verify(listener, times(3)).testStarted(argument.capture());
    verify(listener, times(3)).testFinished(Mockito.any());
    verify(listener, times(0)).testAssumptionFailure(Mockito.any());
    verify(listener, times(1)).testFailure(Mockito.any());

    for (Description d : argument.getAllValues()) {
        assertTrue(d.getTestClass().equals(ValidTest.class));
        assertTrue(d.getChildren().isEmpty());

    }

}
 
开发者ID:richard-melvin,项目名称:junit-theory-suite,代码行数:21,代码来源:TheorySuiteTest.java

示例6: simpleValidTestFilteredTestMethod

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
@Test
public void simpleValidTestFilteredTestMethod() throws Exception {

    RunListener listener = runTestCaseWithMockListener(ValidTest.class,
            Description.createTestDescription(ValidTest.class, "simplePassingTest"));

    ArgumentCaptor<Description> argument = ArgumentCaptor.forClass(Description.class);

    verify(listener, times(1)).testRunStarted(Mockito.any());
    verify(listener, times(1)).testStarted(argument.capture());
    verify(listener, times(1)).testFinished(Mockito.any());
    verify(listener, times(0)).testAssumptionFailure(Mockito.any());
    verify(listener, times(0)).testFailure(Mockito.any());

    assertEquals("simplePassingTest", argument.getValue().getMethodName());
    assertEquals(ValidTest.class, argument.getValue().getTestClass());
    assertEquals(0, argument.getValue().getChildren().size());

}
 
开发者ID:richard-melvin,项目名称:junit-theory-suite,代码行数:20,代码来源:TheorySuiteTest.java

示例7: simpleValidTestFilteredTheory

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
@Test
public void simpleValidTestFilteredTheory() throws Exception {

    RunListener listener = runTestCaseWithMockListener(ValidTest.class,
            Description.createTestDescription(ValidTest.class, "simpleFailingTheory[true]"));

    ArgumentCaptor<Description> argument = ArgumentCaptor.forClass(Description.class);

    verify(listener, times(1)).testRunStarted(Mockito.any());
    verify(listener, times(1)).testStarted(argument.capture());
    verify(listener, times(1)).testFinished(Mockito.any());
    verify(listener, times(0)).testAssumptionFailure(Mockito.any());
    verify(listener, times(0)).testFailure(Mockito.any());

    assertEquals("simpleFailingTheory[true]", argument.getValue().getMethodName());
    assertEquals(ValidTest.class, argument.getValue().getTestClass());
    assertEquals(0, argument.getValue().getChildren().size());

}
 
开发者ID:richard-melvin,项目名称:junit-theory-suite,代码行数:20,代码来源:TheorySuiteTest.java

示例8: addListeners

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
private void addListeners(List<RunListener> listeners, JUnitCore testRunner,
                          PrintStream writer) {
    if (getBooleanArgument(ARGUMENT_SUITE_ASSIGNMENT)) {
        listeners.add(new SuiteAssignmentPrinter());
    } else {
        listeners.add(new TextListener(writer));
        listeners.add(new LogRunListener());
        mInstrumentationResultPrinter = new InstrumentationResultPrinter();
        listeners.add(mInstrumentationResultPrinter);
        listeners.add(new ActivityFinisherRunListener(this,
                new ActivityFinisher()));
        addDelayListener(listeners);
        addCoverageListener(listeners);
    }

    addListenersFromArg(listeners, writer);
    addListenersFromManifest(listeners, writer);

    for (RunListener listener : listeners) {
        testRunner.addListener(listener);
        if (listener instanceof InstrumentationRunListener) {
            ((InstrumentationRunListener) listener).setInstrumentation(this);
        }
    }
}
 
开发者ID:mg6maciej,项目名称:android-groovy-dagger-espresso-demo,代码行数:26,代码来源:AndroidSpockRunner.java

示例9: addDelayListener

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
/**
 * Sets up listener to inject {@link #ARGUMENT_DELAY_MSEC}, if specified.
 */
private void addDelayListener(List<RunListener> list) {
    try {
        Object delay = getArguments().get(ARGUMENT_DELAY_MSEC);  // Accept either string or int
        if (delay != null) {
            int delayMsec = Integer.parseInt(delay.toString());
            list.add(new DelayInjector(delayMsec));
        } else if (getBooleanArgument(ARGUMENT_LOG_ONLY)
                && Build.VERSION.SDK_INT < 16) {
            // On older platforms, collecting tests can fail for large volume of tests.
            // Insert a small delay between each test to prevent this
            list.add(new DelayInjector(15 /* msec */));
        }
    } catch (NumberFormatException e) {
        Log.e(LOG_TAG, "Invalid delay_msec parameter", e);
    }
}
 
开发者ID:mg6maciej,项目名称:android-groovy-dagger-espresso-demo,代码行数:20,代码来源:AndroidSpockRunner.java

示例10: addListenersFromManifest

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
/**
 * Load the listeners specified via meta-data name="listener" in the AndroidManifest.
 */
private void addListenersFromManifest(List<RunListener> listeners,
                                      PrintStream writer) {
    PackageManager pm = getContext().getPackageManager();
    try {
        InstrumentationInfo instrInfo = pm.getInstrumentationInfo(getComponentName(),
                PackageManager.GET_META_DATA);
        Bundle b = instrInfo.metaData;
        if (b == null) {
            return;
        }
        String extraListenerList = b.getString(ARGUMENT_LISTENER);
        addListenersFromClassString(extraListenerList, listeners, writer);
    } catch (NameNotFoundException e) {
        // should never happen
        Log.wtf(LOG_TAG, String.format("Could not find component %s", getComponentName()));
    }
}
 
开发者ID:mg6maciej,项目名称:android-groovy-dagger-espresso-demo,代码行数:21,代码来源:AndroidSpockRunner.java

示例11: ListeningCucumber

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
/**
 *
 * @param clazz Set the feature class
 * @throws InitializationError if there is a problem initializing the test
 * @throws IOException if there is a problem reading a file
 */
public ListeningCucumber(final Class clazz)
		throws InitializationError, IOException {
	super(clazz);
	Listener listenerAnnotation = (Listener) clazz
			.getAnnotation(Listener.class);
	if (listenerAnnotation != null) {
		try {
			listener = (RunListener) listenerAnnotation.value()
					.newInstance();
		} catch (InstantiationException ie) {
			throw new InitializationError(ie);
		} catch (IllegalAccessException iae) {
			throw new InitializationError(iae);
		}
	}
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:23,代码来源:ListeningCucumber.java

示例12: run

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
/**
 * Runs the test classes given in {@param classes}.
 *
 * @returns Zero if all tests pass, non-zero otherwise.
 */
public static int run(Class[] classes, RunListener listener, PrintStream out) {
    JUnitCore junitCore = new JUnitCore();
    junitCore.addListener(listener);
    boolean hasError = false;
    int numTests = 0;
    int numFailures = 0;
    long start = System.currentTimeMillis();
    for (@AutoreleasePool Class c : classes) {
        out.println("Running " + c.getName());
        Result result = junitCore.run(c);
        numTests += result.getRunCount();
        numFailures += result.getFailureCount();
        hasError = hasError || !result.wasSuccessful();
    }
    long end = System.currentTimeMillis();
    out.println(String.format("Ran %d tests, %d failures. Total time: %s seconds", numTests, numFailures,
            NumberFormat.getInstance().format((double) (end - start) / 1000)));
    return hasError ? 1 : 0;
}
 
开发者ID:yahoo,项目名称:squidb,代码行数:25,代码来源:SquidbTestRunner.java

示例13: shouldReportDescriptionsinCorrectOrder

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
@Test
public void shouldReportDescriptionsinCorrectOrder() {
    JUnitCore jUnit = new JUnitCore();
    jUnit.addListener(new RunListener() {
        @Override
        public void testRunStarted(Description description) throws Exception {
            suiteDescription = description;
        }
    });
    jUnit.run(CuppaRunnerTest.TestsAndTestBlocks.class);

    List<Description> rootDescriptionChildren = suiteDescription
            .getChildren().get(0).getChildren().get(0).getChildren();
    assertThat(rootDescriptionChildren).hasSize(3);
    assertThat(rootDescriptionChildren.get(0).getDisplayName()).startsWith("a");
    assertThat(rootDescriptionChildren.get(1).getDisplayName()).startsWith("b");
    assertThat(rootDescriptionChildren.get(2).getDisplayName()).startsWith("when c");
    assertThat(rootDescriptionChildren.get(2).getChildren().get(0).getDisplayName()).startsWith("d");
}
 
开发者ID:cuppa-framework,项目名称:cuppa,代码行数:20,代码来源:CuppaRunnerTest.java

示例14: testListener

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
@Test
public void testListener() throws Exception {
    JUnitCore runner = new JUnitCore();
    RunListener listener = new RunListener() {
        @Override
        public void testStarted(Description description) {
            assertEquals(Description.createTestDescription(OneTest.class, "testOne"),
                    description);
            count++;
        }
    };

    runner.addListener(listener);
    count = 0;
    Result result = runner.run(OneTest.class);
    assertEquals(1, count);
    assertEquals(1, result.getRunCount());
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:19,代码来源:JUnit38ClassRunnerTest.java

示例15: AcceptanceTestsRunnerTaskScheduler

import org.junit.runner.notification.RunListener; //导入依赖的package包/类
public AcceptanceTestsRunnerTaskScheduler(final Class[] testClasses,
                                          final long initialDelay,
                                          final long period,
                                          final TimeUnit unit,
                                          final List<RunListener> runListeners) {
    this.testClasses = testClasses;
    this.initialDelay = initialDelay;
    this.period = period;
    this.unit = unit;
    this.runListeners = runListeners;
    this.scheduler = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder()
                    .setNameFormat("acceptance-tests-runner")
                    .setDaemon(false)
                    .build());
}
 
开发者ID:atam4j,项目名称:atam4j,代码行数:17,代码来源:AcceptanceTestsRunnerTaskScheduler.java


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