How to use testParameterizedInvocationTwice method of AsyncVerificationTests class

Best Mockingbird code snippet using AsyncVerificationTests.testParameterizedInvocationTwice

Run Mockingbird automation tests on LambdaTest cloud grid

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

AsyncVerificationTests.swift

Source: AsyncVerificationTests.swift Github

copy
1import XCTest
2import Mockingbird
3@testable import MockingbirdTestsHost
4
5class AsyncVerificationTests: XCTestCase {
6  
7  var child: ChildMock!
8  var queue: DispatchQueue!
9  
10  override func setUp() {
11    child = mock(Child.self)
12    queue = DispatchQueue(label: "co.bird.mockingbird.tests")
13  }
14  
15  enum Constants {
16    static let asyncTestTimeout: TimeInterval = 1.0
17  }
18  
19  func callTrivialInstanceMethod(on child: Child, times: UInt = 1) {
20    for _ in 0..<times { child.childTrivialInstanceMethod() }
21  }
22  
23  func callParameterizedInstanceMethod(on child: Child, times: UInt = 1) {
24    for _ in 0..<times { _ = child.childParameterizedInstanceMethod(param1: true, 1) }
25  }
26  
27  func testTrivialInvocationOnce() {
28    let expectation = eventually("childTrivialInstanceMethod() is called") {
29      verify(child.childTrivialInstanceMethod()).wasCalled()
30    }
31    queue.async {
32      self.callTrivialInstanceMethod(on: self.child)
33    }
34    wait(for: [expectation], timeout: Constants.asyncTestTimeout)
35  }
36  func testTrivialInvocationOnce_convenienceWaiter() {
37    eventually("childTrivialInstanceMethod() is called") {
38      verify(child.childTrivialInstanceMethod()).wasCalled()
39    }
40    queue.async {
41      self.callTrivialInstanceMethod(on: self.child)
42    }
43    waitForExpectations(timeout: Constants.asyncTestTimeout)
44  }
45  
46  func testTrivialInvocationTwice() {
47    let expectation = eventually("childTrivialInstanceMethod() is called twice") {
48      verify(child.childTrivialInstanceMethod()).wasCalled(exactly(2))
49    }
50    queue.async {
51      self.callTrivialInstanceMethod(on: self.child, times: 2)
52    }
53    wait(for: [expectation], timeout: Constants.asyncTestTimeout)
54  }
55  func testTrivialInvocationTwice_convenienceWaiter() {
56    eventually("childTrivialInstanceMethod() is called twice") {
57      verify(child.childTrivialInstanceMethod()).wasCalled(exactly(2))
58    }
59    queue.async {
60      self.callTrivialInstanceMethod(on: self.child, times: 2)
61    }
62    waitForExpectations(timeout: Constants.asyncTestTimeout)
63  }
64  
65  func testParameterizedInvocationOnce() {
66    given(child.childParameterizedInstanceMethod(param1: any(), any())) ~> true
67    let expectation = eventually("childParameterizedInstanceMethod(param1:_:) is called once") {
68      verify(child.childParameterizedInstanceMethod(param1: any(), any())).wasCalled()
69    }
70    queue.async {
71      self.callParameterizedInstanceMethod(on: self.child)
72    }
73    wait(for: [expectation], timeout: Constants.asyncTestTimeout)
74  }
75  
76  func testParameterizedInvocationTwice() {
77    given(child.childParameterizedInstanceMethod(param1: any(), any())) ~> true
78    let expectation = eventually("childParameterizedInstanceMethod(param1:_:) is called twice") {
79      verify(child.childParameterizedInstanceMethod(param1: any(), any()))
80        .wasCalled(exactly(2))
81    }
82    queue.async {
83      self.callParameterizedInstanceMethod(on: self.child, times: 2)
84    }
85    wait(for: [expectation], timeout: Constants.asyncTestTimeout)
86  }
87  
88  func testSynchronousInvocations() {
89    given(child.childParameterizedInstanceMethod(param1: any(), any())) ~> true
90    let expectation = eventually("childParameterizedInstanceMethod(param1:_:) is called twice") {
91      verify(child.childParameterizedInstanceMethod(param1: any(), any()))
92        .wasCalled(exactly(2))
93    }
94    callParameterizedInstanceMethod(on: self.child, times: 2)
95    wait(for: [expectation], timeout: Constants.asyncTestTimeout)
96  }
97  func testSynchronousInvocations_convenienceWaiter() {
98    given(child.childParameterizedInstanceMethod(param1: any(), any())) ~> true
99    eventually("childParameterizedInstanceMethod(param1:_:) is called twice") {
100      verify(child.childParameterizedInstanceMethod(param1: any(), any()))
101        .wasCalled(exactly(2))
102    }
103    callParameterizedInstanceMethod(on: self.child, times: 2)
104    waitForExpectations(timeout: Constants.asyncTestTimeout)
105  }
106  
107  func testHandlesPastInvocations() {
108    given(child.childParameterizedInstanceMethod(param1: any(), any())) ~> true
109    callParameterizedInstanceMethod(on: self.child, times: 2)
110    let expectation = eventually("childParameterizedInstanceMethod(param1:_:) is called twice") {
111      verify(child.childParameterizedInstanceMethod(param1: any(), any()))
112        .wasCalled(exactly(2))
113    }
114    wait(for: [expectation], timeout: Constants.asyncTestTimeout)
115  }
116  func testHandlesPastInvocations_convenienceWaiter() {
117    given(child.childParameterizedInstanceMethod(param1: any(), any())) ~> true
118    callParameterizedInstanceMethod(on: self.child, times: 2)
119    eventually("childParameterizedInstanceMethod(param1:_:) is called twice") {
120      verify(child.childParameterizedInstanceMethod(param1: any(), any()))
121        .wasCalled(exactly(2))
122    }
123    waitForExpectations(timeout: Constants.asyncTestTimeout)
124  }
125  
126  
127  // MARK: - Ordered verification compatibility
128  
129  func testAsyncVerification_handlesNestedInOrderVerifications() {
130    let expectation = eventually {
131      inOrder {
132        verify(child.childTrivialInstanceMethod()).wasCalled()
133        verify(child.parentTrivialInstanceMethod()).wasCalled()
134        verify(child.grandparentTrivialInstanceMethod()).wasCalled()
135      }
136    }
137    
138    queue.async {
139      (self.child as Child).childTrivialInstanceMethod()
140      (self.child as Child).parentTrivialInstanceMethod()
141      (self.child as Child).grandparentTrivialInstanceMethod()
142    }
143    
144    wait(for: [expectation], timeout: Constants.asyncTestTimeout)
145  }
146  
147  func testAsyncVerification_handlesNestedInOrderVerifications_withSynchronousInvocations() {
148    let expectation = eventually {
149      inOrder {
150        verify(child.childTrivialInstanceMethod()).wasCalled()
151        verify(child.parentTrivialInstanceMethod()).wasCalled()
152        verify(child.grandparentTrivialInstanceMethod()).wasCalled()
153      }
154    }
155    
156    (self.child as Child).childTrivialInstanceMethod()
157    (self.child as Child).parentTrivialInstanceMethod()
158    (self.child as Child).grandparentTrivialInstanceMethod()
159    
160    wait(for: [expectation], timeout: Constants.asyncTestTimeout)
161  }
162  
163  func testAsyncVerification_handlesNestedInOrderVerifications_receivesPastInvocations() {
164    (self.child as Child).childTrivialInstanceMethod()
165    (self.child as Child).parentTrivialInstanceMethod()
166    (self.child as Child).grandparentTrivialInstanceMethod()
167    
168    let expectation = eventually {
169      inOrder {
170        verify(child.childTrivialInstanceMethod()).wasCalled()
171        verify(child.parentTrivialInstanceMethod()).wasCalled()
172        verify(child.grandparentTrivialInstanceMethod()).wasCalled()
173      }
174    }
175
176    wait(for: [expectation], timeout: Constants.asyncTestTimeout)
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
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)