How to use NumberOfInvocationsCheckerTest class of org.mockito.internal.verification.checkers package

Best Mockito code snippet using org.mockito.internal.verification.checkers.NumberOfInvocationsCheckerTest

Run Mockito automation tests on LambdaTest cloud grid

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

copy
1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.concurrentmockito;
6
7import org.junit.Test;
8import org.junit.runner.JUnitCore;
9import org.junit.runner.Result;
10import org.junit.runner.notification.Failure;
11import org.mockito.MockitoTest;
12import org.mockito.exceptions.base.MockitoAssertionErrorTest;
13import org.mockito.exceptions.base.MockitoExceptionTest;
14import org.mockito.internal.AllInvocationsFinderTest;
15import org.mockito.internal.InvalidStateDetectionTest;
16import org.mockito.internal.creation.bytebuddy.TypeCachingMockBytecodeGeneratorTest;
17import org.mockito.internal.exceptions.ReporterTest;
18import org.mockito.internal.handler.MockHandlerImplTest;
19import org.mockito.internal.invocation.InvocationMatcherTest;
20import org.mockito.internal.invocation.InvocationsFinderTest;
21import org.mockito.internal.matchers.ComparableMatchersTest;
22import org.mockito.internal.matchers.EqualsTest;
23import org.mockito.internal.matchers.MatchersToStringTest;
24import org.mockito.internal.progress.MockingProgressImplTest;
25import org.mockito.internal.progress.TimesTest;
26import org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValuesTest;
27import org.mockito.internal.stubbing.defaultanswers.ReturnsGenericDeepStubsTest;
28import org.mockito.internal.util.MockUtilTest;
29import org.mockito.internal.util.collections.ListUtilTest;
30import org.mockito.internal.verification.DefaultRegisteredInvocationsTest;
31import org.mockito.internal.verification.checkers.MissingInvocationCheckerTest;
32import org.mockito.internal.verification.checkers.MissingInvocationInOrderCheckerTest;
33import org.mockito.internal.verification.checkers.NumberOfInvocationsCheckerTest;
34import org.mockito.internal.verification.checkers.NumberOfInvocationsInOrderCheckerTest;
35import org.mockitousage.basicapi.ReplacingObjectMethodsTest;
36import org.mockitousage.basicapi.ResetTest;
37import org.mockitousage.basicapi.UsingVarargsTest;
38import org.mockitousage.examples.use.ExampleTest;
39import org.mockitousage.matchers.CustomMatchersTest;
40import org.mockitousage.matchers.InvalidUseOfMatchersTest;
41import org.mockitousage.matchers.MatchersTest;
42import org.mockitousage.matchers.VerificationAndStubbingUsingMatchersTest;
43import org.mockitousage.misuse.InvalidUsageTest;
44import org.mockitousage.puzzlers.BridgeMethodPuzzleTest;
45import org.mockitousage.puzzlers.OverloadingPuzzleTest;
46import org.mockitousage.stacktrace.ClickableStackTracesTest;
47import org.mockitousage.stacktrace.PointingStackTraceToActualInvocationTest;
48import org.mockitousage.stacktrace.StackTraceFilteringTest;
49import org.mockitousage.stubbing.BasicStubbingTest;
50import org.mockitousage.stubbing.ReturningDefaultValuesTest;
51import org.mockitousage.stubbing.StubbingWithThrowablesTest;
52import org.mockitousage.verification.*;
53import org.mockitoutil.TestBase;
54
55import java.util.Collections;
56import java.util.HashSet;
57import java.util.LinkedList;
58import java.util.List;
59import java.util.Set;
60
61import static org.junit.Assert.assertEquals;
62
63public class ThreadsRunAllTestsHalfManualTest extends TestBase {
64
65    private static class AllTestsRunner extends Thread {
66
67        private Set<Class<?>> failed = new HashSet<Class<?>>();
68
69        public void run() {
70            Result result = JUnitCore.runClasses(
71                    EqualsTest.class,
72                    ListUtilTest.class,
73                    MockingProgressImplTest.class,
74                    TimesTest.class,
75                    MockHandlerImplTest.class,
76                    AllInvocationsFinderTest.class,
77                    ReturnsEmptyValuesTest.class,
78                    NumberOfInvocationsCheckerTest.class,
79                    DefaultRegisteredInvocationsTest.class,
80                    MissingInvocationCheckerTest.class,
81                    NumberOfInvocationsInOrderCheckerTest.class,
82                    MissingInvocationInOrderCheckerTest.class,
83                    TypeCachingMockBytecodeGeneratorTest.class,
84                    InvocationMatcherTest.class,
85                    InvocationsFinderTest.class,
86                    MockitoTest.class,
87                    MockUtilTest.class,
88                    ReporterTest.class,
89                    MockitoAssertionErrorTest.class,
90                    MockitoExceptionTest.class,
91                    StackTraceFilteringTest.class,
92                    BridgeMethodPuzzleTest.class,
93                    OverloadingPuzzleTest.class,
94                    InvalidUsageTest.class,
95                    UsingVarargsTest.class,
96                    CustomMatchersTest.class,
97                    ComparableMatchersTest.class,
98                    InvalidUseOfMatchersTest.class,
99                    MatchersTest.class,
100                    MatchersToStringTest.class,
101                    VerificationAndStubbingUsingMatchersTest.class,
102                    BasicStubbingTest.class,
103                    ReturningDefaultValuesTest.class,
104                    StubbingWithThrowablesTest.class,
105                    AtMostXVerificationTest.class,
106                    BasicVerificationTest.class,
107                    ExactNumberOfTimesVerificationTest.class,
108                    VerificationInOrderTest.class,
109                    NoMoreInteractionsVerificationTest.class,
110                    SelectedMocksInOrderVerificationTest.class,
111                    VerificationOnMultipleMocksUsingMatchersTest.class,
112                    VerificationUsingMatchersTest.class,
113                    RelaxedVerificationInOrderTest.class,
114                    DescriptiveMessagesWhenVerificationFailsTest.class,
115                    DescriptiveMessagesWhenTimesXVerificationFailsTest.class,
116                    BasicVerificationInOrderTest.class,
117                    VerificationInOrderMixedWithOrdiraryVerificationTest.class,
118                    DescriptiveMessagesOnVerificationInOrderErrorsTest.class,
119                    InvalidStateDetectionTest.class,
120                    ReplacingObjectMethodsTest.class,
121                    ClickableStackTracesTest.class,
122                    ExampleTest.class,
123                    PointingStackTraceToActualInvocationTest.class,
124                    VerificationInOrderFromMultipleThreadsTest.class,
125                    ResetTest.class,
126                    ReturnsGenericDeepStubsTest.class
127                );
128
129                if (!result.wasSuccessful()) {
130                    System.err.println("Thread[" + Thread.currentThread().getId() + "]: error!");
131                    List<Failure> failures = result.getFailures();
132                    System.err.println(failures.size());
133                    for (Failure failure : failures) {
134                        System.err.println(failure.getTrace());
135                        failed.add(failure.getDescription().getTestClass());
136                    }
137                }
138        }
139
140        public Set<Class<?>> getFailed() {
141            return failed;
142        }
143    }
144
145    @Test
146    public void shouldRunInMultipleThreads() throws Exception {
147        //this test ALWAYS fails if there is a single failing unit
148        assertEquals("Run in multiple thread failed for tests", Collections.emptySet(), runInMultipleThreads(3));
149    }
150
151    public static Set<Class<?>> runInMultipleThreads(int numberOfThreads) throws Exception {
152        List<AllTestsRunner> threads = new LinkedList<AllTestsRunner>();
153        for (int i = 1; i <= numberOfThreads; i++) {
154            threads.add(new AllTestsRunner());
155        }
156
157        for (Thread t : threads) {
158            t.start();
159        }
160
161        Set<Class<?>> failed = new HashSet<Class<?>>();
162        for (AllTestsRunner t : threads) {
163            t.join();
164            failed.addAll(t.getFailed());
165        }
166
167        return failed;
168    }
169
170    public static void main(String[] args) throws Exception {
171        int numberOfThreads = 20;
172        long before = System.currentTimeMillis();
173        Set<Class<?>> failed = runInMultipleThreads(numberOfThreads);
174        long after = System.currentTimeMillis();
175        long executionTime = (after-before)/1000;
176        System.out.println("Finished tests in " + numberOfThreads + " threads in " + executionTime + " seconds. (" + failed.size() + " tests failed)");
177    }
178}
179
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 NumberOfInvocationsCheckerTest

    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)