-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from KaoruMuta/feature/test
test: add unittest and uitest to improve code coverage
- Loading branch information
Showing
8 changed files
with
148 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
IGStoryButtonKitTests/Helper/Extension/XCTest+Precondition.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// XCTest+Precondition.swift | ||
// IGStoryButtonKitTests | ||
// | ||
// Created by k_muta on 2021/01/12. | ||
// | ||
|
||
import XCTest | ||
|
||
extension XCTestCase { | ||
func expectPreconditionFailure(expectedMessage: String, block: () -> ()) { | ||
let expect = expectation(description: "failing precondition") | ||
preconditionClosure = { | ||
(condition, message, file, line) in | ||
if !condition { | ||
expect.fulfill() | ||
XCTAssertEqual(message, expectedMessage, "precondition message didn't match", file: file, line: line) | ||
} | ||
} | ||
block() | ||
waitForExpectations(timeout: 2.0, handler: nil) | ||
preconditionClosure = defaultPreconditionClosure | ||
} | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
IGStoryButtonKitTests/Helper/Mock/MockViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// MockViewController.swift | ||
// IGStoryButtonKitTests | ||
// | ||
// Created by k_muta on 2021/01/11. | ||
// | ||
|
||
import UIKit | ||
|
||
final class MockViewController: UIViewController, IGStoryButtonDelegate { | ||
var isTapped: Bool = false | ||
var isLongPressed: Bool = false | ||
|
||
func didTapped() { | ||
isTapped = true | ||
} | ||
|
||
func didLongPressed() { | ||
isLongPressed = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Precondition.swift | ||
// IGStoryButtonKitTests | ||
// | ||
// Created by k_muta on 2021/01/12. | ||
// | ||
|
||
import Foundation | ||
|
||
func precondition(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = String(), file: StaticString = #file, line: UInt = #line) { | ||
preconditionClosure(condition(), message(), file, line) | ||
} | ||
|
||
var preconditionClosure: (Bool, String, StaticString, UInt) -> () = defaultPreconditionClosure | ||
let defaultPreconditionClosure = { Swift.precondition($0, $1, file: $2, line: $3) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters