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
Asked
Active
Viewed 7,865 times
1 Answers
12
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.

Oletha
- 7,324
- 1
- 26
- 46
-
1Say on the tap of a button i change the color of a view, can this be validated with XCTest Unit tests? – abhishek saatal Jul 31 '16 at 14:56
-
You can validate that the background color is changed when the @IBAction method is called. – Oletha Jul 31 '16 at 20:45
-
but in unit testing you cannot automatically tap for the action to be triggered , there is no record mode available. – abhishek saatal Aug 01 '16 at 10:59
-
2@abhisheksaatal Oletha meant you have to instantiate your view controller on an Unit Test, call method that must change the button's background and check it through `XCTAssertTrue(button.backgroundColor == UIColor.redColor())` for example. – djserva Aug 01 '16 at 13:40
-
2Yes, though I would advise using XCTAssertEqual for better error messaging in this scenario. – Oletha Aug 01 '16 at 13:50
-
Yes though i accept that it is one of the way for doing it, but it will be too hectic to compare color of each and every UIView and assert on it, it would require lot of time to do so, however image comparison can be done easily. XCTest UITesting does not provide a way to do it, XCTest unit test will require a lot of effort to do it. – abhishek saatal Aug 02 '16 at 08:28