Search in sources :

Example 16 with JUnitCore

use of org.junit.runner.JUnitCore in project mockito by mockito.

the class UnusedStubsExceptionMessageTest method lists_all_unused_stubs_cleanly.

@Test
public void lists_all_unused_stubs_cleanly() {
    JUnitCore runner = new JUnitCore();
    //when
    Result result = runner.run(HasUnnecessaryStubs.class);
    //then
    Failure failure = result.getFailures().get(0);
    assertEquals("\n" + "Unnecessary stubbings detected in test class: HasUnnecessaryStubs\n" + "Clean & maintainable test code requires zero unnecessary code.\n" + "Following stubbings are unnecessary (click to navigate to relevant line of code):\n" + "  1. -> at org.mockitousage.junitrunner.UnusedStubsExceptionMessageTest$HasUnnecessaryStubs.<init>(UnusedStubsExceptionMessageTest.java:0)\n" + "  2. -> at org.mockitousage.junitrunner.UnusedStubsExceptionMessageTest$HasUnnecessaryStubs.<init>(UnusedStubsExceptionMessageTest.java:0)\n" + "Please remove unnecessary stubbings or use 'silent' option. More info: javadoc for UnnecessaryStubbingException class.", filterLineNo(failure.getException().getMessage()));
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 17 with JUnitCore

use of org.junit.runner.JUnitCore in project mockito by mockito.

the class VerificationListenerCallBackTest method should_call_verification_listeners.

@Test
public void should_call_verification_listeners() {
    //given
    RememberingListener listener = new RememberingListener();
    MockitoFramework mockitoFramework = Mockito.framework();
    mockitoFramework.addListener(listener);
    JUnitCore runner = new JUnitCore();
    //when
    runner.run(VerificationListenerSample.class);
    //then
    assertThat(listener.mock).isNotNull();
    assertThat(listener.mode).isEqualToComparingFieldByField(times(1));
}
Also used : JUnitCore(org.junit.runner.JUnitCore) MockitoFramework(org.mockito.MockitoFramework) Test(org.junit.Test)

Example 18 with JUnitCore

use of org.junit.runner.JUnitCore in project mockito by mockito.

the class VerboseMockitoRunnerTest method shouldNotContainWarnings.

@Test
@Ignore
public void shouldNotContainWarnings() throws Exception {
    Result result = new JUnitCore().run(NoWarnings.class);
    assertEquals(1, result.getFailures().size());
    assertEquals("boo", result.getFailures().get(0).getException().getMessage());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Result(org.junit.runner.Result) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with JUnitCore

use of org.junit.runner.JUnitCore in project mockito by mockito.

the class InvalidUseOfMatchersTest method should_mention_matcher_when_misuse_detected.

@Test
public void should_mention_matcher_when_misuse_detected() {
    // Given
    // When
    Result run = new JUnitCore().run(ObjectMatcherMisuseOnPrimitiveSite.class);
    // Then
    assertThat(run.getFailures()).hasSize(2);
    assertThat(run.getFailures().get(0).getException()).isInstanceOf(NullPointerException.class).hasMessage(null);
    assertThat(run.getFailures().get(1).getException()).isInstanceOf(InvalidUseOfMatchersException.class).hasMessageContaining("primitive alternatives");
    new StateMaster().reset();
}
Also used : InvalidUseOfMatchersException(org.mockito.exceptions.misusing.InvalidUseOfMatchersException) JUnitCore(org.junit.runner.JUnitCore) StateMaster(org.mockito.StateMaster) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 20 with JUnitCore

use of org.junit.runner.JUnitCore in project junit4 by junit-team.

the class CategoriesAndParameterizedTest method runsTestMethodWithCategory.

@Test
public void runsTestMethodWithCategory() {
    Result result = new JUnitCore().run(SuiteWithParameterizedTestWithMethodWithCategory.class);
    assertEquals(2, result.getRunCount());
    assertEquals(0, result.getFailureCount());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Result(org.junit.runner.Result) Test(org.junit.Test)

Aggregations

JUnitCore (org.junit.runner.JUnitCore)173 Result (org.junit.runner.Result)104 Test (org.junit.Test)88 Request (org.junit.runner.Request)33 Failure (org.junit.runner.notification.Failure)24 PrintableResult.testResult (org.junit.experimental.results.PrintableResult.testResult)22 RunListener (org.junit.runner.notification.RunListener)17 Description (org.junit.runner.Description)16 ArrayList (java.util.ArrayList)14 TestResult (junit.framework.TestResult)14 TextListener (org.junit.internal.TextListener)12 Runner (org.junit.runner.Runner)9 RandomizedRunner (com.carrotsearch.randomizedtesting.RandomizedRunner)7 TestSuiteModel (com.google.testing.junit.runner.model.TestSuiteModel)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 OutputStream (java.io.OutputStream)5 CategoryFilter (org.junit.experimental.categories.Categories.CategoryFilter)5 File (java.io.File)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 InOrder (org.mockito.InOrder)4