Created
April 18, 2018 11:52
-
-
Save damodarnamala/789dfc142fd492a56c556b844ce945e9 to your computer and use it in GitHub Desktop.
IOS Unit Testing Code Coverage
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
import XCTest | |
class LoginSpec: XCTestCase { | |
var login: LoginViewModel? | |
override func setUp() { | |
super.setUp() | |
login = LoginViewModel() | |
print("\n Method Calling \n") | |
} | |
override func tearDown() { | |
// Put teardown code here. This method is called after the invocation of each test method in the class. | |
super.tearDown() | |
} | |
func testExample() { | |
let isLoginSuccess = login?.login(userName: "Damodar", password: "password") | |
XCTAssertEqual(isLoginSuccess, true, "Username or password is wrong") | |
// This is an example of a functional test case. | |
// Use XCTAssert and related functions to verify your tests produce the correct results. | |
} | |
func testPerformanceExample() { | |
// This is an example of a performance test case. | |
self.measure { | |
// Put the code you want to measure the time of here. | |
} | |
} | |
} |
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
import Foundation | |
class LoginViewModel { | |
func login(userName: String, password: String) -> Bool { | |
if userName.characters.count > 0 && password.characters.count > 0 { | |
return true | |
} | |
return false | |
} | |
} |
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
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var textFieldName : UITextField! | |
@IBOutlet weak var textFieldPassword : UITextField! | |
@IBOutlet weak var submitButton : UIButton! | |
let loginModel = LoginViewModel() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
@IBAction func submitAction(sender: UIButton) { | |
let isValidLogin = loginModel.login(userName: (self.textFieldName?.text)!, password: (self.textFieldPassword?.text)!) | |
assert(isValidLogin == true, "Login failed ") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment