Saturday, November 7, 2026
HomeiOS Developmentios - Swift unit check can't change the info to check the...

ios – Swift unit check can’t change the info to check the operate

[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]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments