0

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!

Lilya
  • 495
  • 6
  • 20
  • Does this answer your question? [Testing if an element is visible with Xcode 7 UITest](https://stackoverflow.com/questions/33247116/testing-if-an-element-is-visible-with-xcode-7-uitest) – Cristik Jan 24 '20 at 12:13
  • Not really. I have a UIView which has a label that is visible only when a UIView is tapped on. When tapped on, my label becomes visible and shows a current date&time. The problem is that I don't even know how to reach this label to test for visibility. Everything I have tried so far doesn't seem to be working for my case. – Lilya Jan 24 '20 at 12:21

1 Answers1

0

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

Shivam Gaur
  • 491
  • 5
  • 16