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