How to use testExactParameterMatching method of ObjectiveCParameterTests class

Best Mockingbird code snippet using ObjectiveCParameterTests.testExactParameterMatching

Run Mockingbird automation tests on LambdaTest cloud grid

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

ObjectiveCParameterTests.swift

Source: ObjectiveCParameterTests.swift Github

copy
1import Mockingbird
2@testable import MockingbirdTestsHost
3import XCTest
4
5class ObjectiveCParameterTests: BaseTestCase {
6  
7  var parametersMock: ObjCParametersMock!
8  var parametersInstance: ObjCParameters { parametersMock }
9  
10  override func setUpWithError() throws {
11    self.parametersMock = mock(ObjCParameters.self)
12  }
13  
14  func testExactParameterMatching() {
15    let instance = NSViewController()
16    given(parametersMock.method(value: instance)).willReturn(true)
17    XCTAssertTrue(parametersInstance.method(value: instance))
18    verify(parametersMock.method(value: instance)).wasCalled()
19  }
20  func testExactParameterMatching_stubbingOperator() {
21    let instance = NSViewController()
22    given(parametersMock.method(value: instance)) ~> true
23    XCTAssertTrue(parametersInstance.method(value: instance))
24    verify(parametersMock.method(value: instance)).wasCalled()
25  }
26  
27  func testExactNilParameterMatching() {
28    given(parametersMock.method(optionalValue: nil)).willReturn(true)
29    XCTAssertTrue(parametersInstance.method(optionalValue: nil))
30    verify(parametersMock.method(optionalValue: nil)).wasCalled()
31  }
32  func testExactNilParameterMatching_stubbingOperator() {
33    given(parametersMock.method(optionalValue: nil)) ~> true
34    XCTAssertTrue(parametersInstance.method(optionalValue: nil))
35    verify(parametersMock.method(optionalValue: nil)).wasCalled()
36  }
37  
38  func testWildcardParameterMatchingAny() {
39    given(parametersMock.method(value: any())).willReturn(true)
40    XCTAssertTrue(parametersInstance.method(value: NSViewController()))
41    verify(parametersMock.method(value: any())).wasCalled()
42  }
43  func testWildcardParameterMatchingAny_stubbingOperator() {
44    given(parametersMock.method(value: any())) ~> true
45    XCTAssertTrue(parametersInstance.method(value: NSViewController()))
46    verify(parametersMock.method(value: any())).wasCalled()
47  }
48  
49  func testWildcardOptionalParameterMatchingAny() {
50    given(parametersMock.method(optionalValue: any())).willReturn(true)
51    XCTAssertTrue(parametersInstance.method(optionalValue: nil))
52    verify(parametersMock.method(optionalValue: any())).wasCalled()
53  }
54  func testWildcardOptionalParameterMatchingAny_stubbingOperator() {
55    given(parametersMock.method(optionalValue: any())) ~> true
56    XCTAssertTrue(parametersInstance.method(optionalValue: nil))
57    verify(parametersMock.method(optionalValue: any())).wasCalled()
58  }
59  
60  func testWildcardParameterMatchingAnyWhere() {
61    let instance = NSViewController()
62    given(parametersMock.method(value: any(where: { $0 === instance }))).willReturn(true)
63    XCTAssertTrue(parametersInstance.method(value: instance))
64    verify(parametersMock.method(value: any(where: { $0 === instance }))).wasCalled()
65  }
66  func testWildcardParameterMatchingAnyWhere_stubbingOperator() {
67    let instance = NSViewController()
68    given(parametersMock.method(value: any(where: { $0 === instance }))) ~> true
69    XCTAssertTrue(parametersInstance.method(value: instance))
70    verify(parametersMock.method(value: any(where: { $0 === instance }))).wasCalled()
71  }
72  
73  func testWildcardParameterMatchingNotNil() {
74    given(parametersMock.method(value: notNil())).willReturn(true)
75    XCTAssertTrue(parametersInstance.method(value: NSViewController()))
76    verify(parametersMock.method(value: notNil())).wasCalled()
77  }
78  func testWildcardParameterMatchingNotNil_stubbingOperator() {
79    given(parametersMock.method(value: notNil())) ~> true
80    XCTAssertTrue(parametersInstance.method(value: NSViewController()))
81    verify(parametersMock.method(value: notNil())).wasCalled()
82  }
83  
84  func testWildcardOptionalParameterMatchingNotNil() {
85    given(parametersMock.method(optionalValue: notNil())).willReturn(true)
86    XCTAssertTrue(parametersInstance.method(optionalValue: NSViewController()))
87    verify(parametersMock.method(optionalValue: notNil())).wasCalled()
88  }
89  func testWildcardOptionalParameterMatchingNotNil_stubbingOperator() {
90    given(parametersMock.method(optionalValue: notNil())) ~> true
91    XCTAssertTrue(parametersInstance.method(optionalValue: NSViewController()))
92    verify(parametersMock.method(optionalValue: notNil())).wasCalled()
93  }
94  
95  func testWildcardOptionalParameterDoesNotMatchNil() {
96    shouldFail {
97      given(self.parametersMock.method(optionalValue: notNil())).willReturn(true)
98      XCTAssertTrue(self.parametersInstance.method(optionalValue: nil))
99    }
100  }
101  func testWildcardOptionalParameterDoesNotMatchNil_stubbingOperator() {
102    shouldFail {
103      given(self.parametersMock.method(optionalValue: notNil())) ~> true
104      XCTAssertTrue(self.parametersInstance.method(optionalValue: nil))
105    }
106  }
107}
108
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)