简体   繁体   中英

How do I write a UI test in Swift to test whether a label becomes visible if a button is tapped on?

I am a total beginner in both Swift and UI/Unit testing.

The goal is to test if a label is visible when a view is tapped on. Yes, a view. The problem is that my 'button' is a UIView class and my label is an @IBInspectable computed property inside of this UIView class. So, I am kind of perplexed about how I test.

Would appreciate any recommendations on where I can find nice explanations about UI/Unit Testing in general. :) Thanks!

Hi the thing is you need to test the function which is called on tapping the button right.

Im assuming you are not using Swift only.

So some basic steps can be

  1. check for the visibilty of the button in your testcase class before mocking the button tap.
  2. for mocking the button tap you can call button.sendActions(for: .touchUpInside)
  3. now check the visibilty of the button. Here you can simply use XCAssertTrue and XCAssertFalse for checking the button visibility

Some Usefull links -

https://useyourloaf.com/blog/ui-testing-quick-guide/

https://www.raywenderlich.com/960290-ios-unit-testing-and-ui-testing-tutorial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM