Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Unit Testing IBAction

I have a UIViewController that contains each of UITextField, UIButton and UILabel. I put something in the UITextField, press a button and the string is now capitalized in the UILabel.

My question is: how do I set up the IBAction in Swift for unit tests? If there is no way to test the action in Swift, what else can I do to test this?

like image 213
noobsmcgoobs Avatar asked May 11 '26 00:05

noobsmcgoobs


1 Answers

In the unit-testing world, the most difficult work could be UI testing. So, what you can do is to check whatever is available to you from the API.

You can not toggle an action or event like you are a phone user. So, you have to programmatically toggle actions or events in order to test on that. You will also have to programmatically initialize the UI elements yourself.

IBAction is just nothing but an indicator to tell UIStoryboard that this is a connector method, you can ignore and treat it as a normal method.

like image 63
Lucas Huang Avatar answered May 12 '26 13:05

Lucas Huang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!