Thanks! I really appreciate the feedback.
In answer to your question, I personally think it’s overkill to test constraints. I think it’s up to every developer to draw the line on where they stop testing and for me that line is constraints.
This article http://merowing.info/2017/01/testing-ios-apps/ mentions using snapshot testing (https://www.objc.io/issues/15-testing/snapshot-testing/). I think this is probably the best way to test if everything is pixel perfect.
I do however think it’s useful to use TDD to build my view. For instance I’ll use TDD to create a component that contains a UITextField and a UIButton and I’ll call it “TextFieldButtonView”. Then I’ll write a test to make sure my ViewController contains a TextFieldButtonView, and configures it correctly. I won’t test that it’s in the top left corner, but I will probably include a basic sanity check that isn’t hidden for instance.
This also highlights the importance of testing on glass. I could write tests to assert that TextFieldButtonView:
- isn’t obstructed by another view
- doesn’t have it’s origin offscreen
- isn’t one pixel tall
But I don’t think it’s worth it. For me TDD is about helping me think about and drive the design of my code. I don’t see how those types of tests help me achieve any of the goals I normally associate with TDD:
- robust models
- good design
- internal api documentation
- confidence in refactoring