[ad_1]
I’m making use of unit check in viewController. Name the viewController and viewModel and attempt to change worth to check totally different validation. Nonetheless, when i modify the worth in unit check, the operate “validateSalutation” in viewController can’t print the replace worth (i can instantly change the worth inside operate, however can’t do it in unit check).
I’m questioning easy methods to do a unit check like these….. additionally the unit check for personal technique. Please Assist
import XCTest
@testable myProject
class RegFormViewControllerTests: XCTestCase {
var formEditviewModel: RegFormViewModel!
var formEditController: RegFormViewController!
override func setUp() {
formEditviewModel = RegFormViewModel()
formEditController = RegFormViewController(
viewModel: formEditviewModel
)
}
func test_isSalutationValid() {
formEditviewModel.salutationInputViewModel.inputValue = "Miss"
// I can print the worth "Miss" right here, however within the operate "validateSalution", i can't see the up to date worth
var end result = formEditController.validateSalutation()
XCTAssertFalse(end result)
}
}
class RegFormViewController: UIViewController {
var formEditviewModel: RegFormViewModel!
func validateSalutation() -> Bool {
var isValid = false
let salutation = formEditviewModel.salutationInputViewModel.inputValue
print(salutation) // it's empty additionally when i modify the worth in unit check name this operate
if (!salutation.isEmpty) {
isValid = true
}
return isValid
}
}
[ad_2]
