How to use testInitializerClass method of InitializerTests class

Best Mockingbird code snippet using InitializerTests.testInitializerClass

Run Mockingbird automation tests on LambdaTest cloud grid

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

InitializerTests.swift

Source: InitializerTests.swift Github

copy
1//
2//  InitializerTests.swift
3//  MockingbirdTests
4//
5//  Created by Andrew Chang on 9/5/19.
6//
7
8import XCTest
9import Mockingbird
10@testable import MockingbirdTestsHost
11
12class InitializerTests: XCTestCase {
13  
14  // MARK: Standard initialization
15  
16  var initializerClass: InitializerClassMock!
17  var initializerProtocol: InitializerProtocolMock!
18  
19  func testInitializerClass() {
20    initializerClass = mock(InitializerClass.self).initialize()
21    initializerClass = mock(InitializerClass.self).initialize(param: true)
22    initializerClass = mock(InitializerClass.self).initialize(param: 1)
23    initializerClass = try! mock(InitializerClass.self).initialize(param: "hello world")
24    initializerClass = mock(InitializerClass.self).initialize(param: Optional<String>(nil))
25  }
26  
27  func testInitializerProtocol() {
28    initializerProtocol = mock(InitializerProtocol.self)
29  }
30  
31  
32  // MARK: Empty type initialization
33  
34  var emptyProtocol: EmptyProtocolMock!
35  var emptyClass: EmptyClassMock!
36  var emptyInheritingProtocol: EmptyInheritingProtocolMock!
37  var emptyInheritingClass: EmptyInheritingClassMock!
38  
39  func testEmptyTypeInitialization() {
40    emptyProtocol = mock(EmptyProtocol.self)
41    emptyClass = mock(EmptyClass.self)
42  }
43  
44  func testEmptyInheritingTypeInitialization() {
45    emptyInheritingProtocol = mock(EmptyInheritingProtocol.self)
46    emptyInheritingClass = mock(EmptyInheritingClass.self)
47  }
48  
49  
50  // MARK: Class only protocol initialization
51  
52  var deprecatedClassOnlyProtocol: DeprecatedClassOnlyProtocolMock!
53  var deprecatedClassOnlyProtocolWithInheritance: DeprecatedClassOnlyProtocolWithInheritanceMock!
54  var classOnlyProtocol: ClassOnlyProtocolMock!
55  var classOnlyProtocolWithInheritance: ClassOnlyProtocolWithInheritanceMock!
56  var openClassConstrainedProtocol: ConformingInitializableOpenClassConstrainedProtocolMock!
57  var nsObjectProtocolConformingProtocol: NSObjectProtocolConformingProtocolMock!
58  var initializableClassOnlyProtocol: InitializableClassOnlyProtocolMock!
59  var initializableClassOnlyProtocolWithInheritedInitializer: InitializableClassOnlyProtocolWithInheritedInitializerMock!
60  
61  func testDeprecatedClassOnlyProtocolInitialization() {
62    deprecatedClassOnlyProtocol = mock(DeprecatedClassOnlyProtocol.self)
63    deprecatedClassOnlyProtocolWithInheritance = mock(DeprecatedClassOnlyProtocolWithInheritance.self)
64  }
65  
66  func testClassOnlyProtocolInitialization() {
67    classOnlyProtocol = mock(ClassOnlyProtocol.self)
68    classOnlyProtocolWithInheritance = mock(ClassOnlyProtocolWithInheritance.self)
69    openClassConstrainedProtocol =
70      mock(ConformingInitializableOpenClassConstrainedProtocol.self).initialize()
71    nsObjectProtocolConformingProtocol = mock(NSObjectProtocolConformingProtocol.self).initialize()
72    initializableClassOnlyProtocol =
73      mock(InitializableClassOnlyProtocol.self).initialize(param1: true, param2: 42)
74    initializableClassOnlyProtocolWithInheritedInitializer =
75      mock(InitializableClassOnlyProtocolWithInheritedInitializer.self).initialize(param: true)
76    initializableClassOnlyProtocolWithInheritedInitializer =
77      mock(InitializableClassOnlyProtocolWithInheritedInitializer.self).initialize(param: 42)
78  }
79  
80  
81  // MARK: - Inferred mock type initialization
82  
83  func testInferredClassMockTypeInitialization() {
84    let child = mock(Child.self)
85    (child as Child).childTrivialInstanceMethod()
86    verify(child.childTrivialInstanceMethod()).wasCalled()
87  }
88  
89  func testInferredProtocolMockTypeInitialization() {
90    let child = mock(ChildProtocol.self)
91    (child as ChildProtocol).childTrivialInstanceMethod()
92    verify(child.childTrivialInstanceMethod()).wasCalled()
93  }
94  
95  func testInferredClassOnlyProtocolMockTypeInitialization() {
96    let classOnlyProtocol = mock(ClassOnlyProtocol.self)
97    given(classOnlyProtocol.getVariable()) ~> true
98    XCTAssertTrue((classOnlyProtocol as ClassOnlyProtocol).variable)
99    verify(classOnlyProtocol.getVariable()).wasCalled()
100  }
101}
102
103
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

Trigger testInitializerClass code on LambdaTest Cloud Grid

Execute automation tests with testInitializerClass on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

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)