У меня разные результаты при попытке проверить ViewController в Swift.Тест для UIViewController терпит неудачу после рефакторинга в Swift
Этот первый код проходит тест.
@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()
}
}
Если я реорганизовать испытание и я двигаюсь создание контроллера представления для переменной экземпляра тест терпит неудачу в линии
@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()
}
}
Да, вы правы. Спасибо огромное! – drasick