Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In XCTest UI Testing, how to check the background color of button, label , views?

I am trying to validate if the background color can be obtained in XCTest UI Testing, I am looking to compare the background color with the set value, so that i don't have to rely on image comparison

like image 241
abhishek saatal Avatar asked Jul 29 '16 21:07

abhishek saatal


People also ask

How do you write test cases for UI testing in Swift?

When you're ready to test, go to a test class and place the cursor inside the test method to record the interaction. From the debug bar, click the Record UI Test button. Xcode will launch the app and run it. You can interact with the element on-screen and perform a sequence of interactions for any UI test.

How do you write UI test cases in SwiftUI?

To create a new UI testing target, go to the Xcode menu File -> New -> Target -> UI Testing bundle. Now we can write our first UI test. To write a UI test, we have to create a Swift class that extends XCTestCase. Xcode runs every method that starts with the word test as a separate test.


1 Answers

XCTest is for functional testing, rather than asserting visual requirements.

To test requirements such as background color, use a unit test to initialize the view controller in question and check the view's background color there. You don't need to rely on image comparison, and unit tests are a lot faster.

like image 72
Oletha Avatar answered Sep 21 '22 10:09

Oletha