I'm having different results in trying to test a ViewController in Swift.
This first code pass the test.
@testable import VideoAudioExtractor
import XCTest
class SecondViewControllerTest: XCTestCase {
let storyBoardName = "Main"
let viewControllerIdentifier = "SecondViewController"
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
func testSelectAudioButtonIsConnected () {
let sut = UIStoryboard(name: storyBoardName, bundle: nil).instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController
let dummy = sut.view
if let unpwarppedOptional = sut.selectAudioButton {
XCTAssertEqual(unpwarppedOptional,sut.selectAudioButton, "correct value")
}
else {
XCTFail("Value isn't set")
}
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
}
If I refactor the test and I move the creation of the view controller to an instance variable the test fails in Line
@testable import VideoAudioExtractor
import XCTest
class SecondViewControllerTest: XCTestCase {
let storyBoardName = "Main"
let viewControllerIdentifier = "SecondViewController"
var sut : SecondViewController {
return UIStoryboard(name: storyBoardName, bundle: nil).instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController
}
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
func testSelectAudioButtonIsConnected () {
let dummy = sut.view
if let unpwarppedOptional = sut.selectAudioButton {
XCTAssertEqual(unpwarppedOptional,sut.selectAudioButton, "correct value")
}
else {
XCTFail("Value isn't set")
}
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
}
Aucun commentaire:
Enregistrer un commentaire