Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import XCTest
- class MyViewModel {
- weak var delegate: MyDelegateProtocol?
- func viewModelFunc() {
- delegate?.myFunc()
- }
- }
- /// Protocol defined in our app.
- protocol MyDelegateProtocol: class {
- func myFunc()
- }
- /// Class, implementing our protocol, defined in the test case.
- class TestMyDelegate: MyDelegateProtocol {
- var myFuncHelper: Bool = false
- func myFunc() {
- myFuncHelper = true
- }
- }
- /// ViewModel we want to test.
- class TestMyViewModel: XCTestCase {
- func testDelegate() {
- let viewModel = MyViewModel()
- let delegate = TestMyDelegate()
- viewModel.delegate = delegate
- XCTAssertFalse(delegate.myFuncHelper)
- viewModel.viewModelFunc()
- XCTAssertTrue(delegate.myFuncHelper)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement