How to use DefaultInternalRunnerTest class of org.mockito.internal.runners package

Best Mockito code snippet using org.mockito.internal.runners.DefaultInternalRunnerTest

Run Mockito automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1/**
2 * Copyright (c) 2017 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.mockito.internal.runners;
6
7
8import org.junit.Assert;
9import org.junit.Test;
10import org.junit.runner.Description;
11import org.junit.runner.notification.Failure;
12import org.junit.runner.notification.RunListener;
13import org.mockito.ArgumentMatchers;
14import org.mockito.Mock;
15import org.mockito.Mockito;
16import org.mockito.internal.junit.MockitoTestListener;
17import org.mockito.internal.junit.TestFinishedEvent;
18import org.mockito.internal.util.Supplier;
19
20
21public class DefaultInternalRunnerTest {
22    private final RunListener runListener = Mockito.mock(RunListener.class);
23
24    private final MockitoTestListener mockitoTestListener = Mockito.mock(MockitoTestListener.class);
25
26    private final Supplier<MockitoTestListener> supplier = new Supplier<MockitoTestListener>() {
27        public MockitoTestListener get() {
28            return mockitoTestListener;
29        }
30    };
31
32    @Test
33    public void does_not_fail_when_tests_succeeds() throws Exception {
34        new DefaultInternalRunner(DefaultInternalRunnerTest.SuccessTest.class, supplier).run(newNotifier(runListener));
35        Mockito.verify(runListener, Mockito.never()).testFailure(ArgumentMatchers.any(Failure.class));
36        Mockito.verify(runListener, Mockito.times(1)).testFinished(ArgumentMatchers.any(Description.class));
37        Mockito.verify(mockitoTestListener, Mockito.only()).testFinished(ArgumentMatchers.any(TestFinishedEvent.class));
38    }
39
40    @Test
41    public void does_not_fail_second_test_when_first_test_fail() throws Exception {
42        new DefaultInternalRunner(DefaultInternalRunnerTest.TestFailOnInitialization.class, supplier).run(newNotifier(runListener));
43        Mockito.verify(runListener, Mockito.times(1)).testFailure(ArgumentMatchers.any(Failure.class));
44        Mockito.verify(runListener, Mockito.never()).testFinished(ArgumentMatchers.any(Description.class));
45        Mockito.verify(mockitoTestListener, Mockito.never()).testFinished(ArgumentMatchers.any(TestFinishedEvent.class));
46        Mockito.reset(runListener);
47        new DefaultInternalRunner(DefaultInternalRunnerTest.SuccessTest.class, supplier).run(newNotifier(runListener));
48        Mockito.verify(runListener, Mockito.never()).testFailure(ArgumentMatchers.any(Failure.class));
49        Mockito.verify(runListener, Mockito.times(1)).testFinished(ArgumentMatchers.any(Description.class));
50        Mockito.verify(mockitoTestListener, Mockito.only()).testFinished(ArgumentMatchers.any(TestFinishedEvent.class));
51    }
52
53    public static final class SuccessTest {
54        @Test
55        public void this_test_is_NOT_supposed_to_fail() {
56            Assert.assertTrue(true);
57        }
58    }
59
60    public static final class TestFailOnInitialization {
61        @Mock
62        private System system;
63
64        @Test
65        public void this_test_is_supposed_to_fail() {
66            Assert.assertNotNull(system);
67        }
68    }
69}
70
71
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on DefaultInternalRunnerTest

    No relevant questions found for this class 😞

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)