Confusion regarding Android and TDD
I'm currently reading books and articles about Test Driven Development, both in the case of Android development and about TDD in general. I'm a bit confused about testing the GUI.
In this book the author writes test even for designing the GUI for an example application. For things like "an EditText's margin sh开发者_JAVA百科ould be 5 pixels wide". Does this really make sense? I can understand the value in writing test for specific functions (e.g. does my unit converter app convert 5 meters correctly into inches?), but should I really test if I defined my UI widgets correctly in the layout xml file?
I usually have to develop UIs that are much more complex than the 2-EditTexts-below-each-other scenario. I think it'd be a complete waste of time to write tests to check if I defined the font sizes to be 22dip or not. Am I getting the wrong idea?
Test what you think can break. If you don't think the EditText's margin will ever change - don't worry about it. But think about the ways it could change. Beyond the obvious one of changing the value in the XML, you might decide for the sake of simplicity, consistency, and reduced line count that you want to use styles and themes. Now that individual element's margin can change because its theme changed - or because the theme on which it was based changed, etc.
I think you're right; it sounds like the book (which I haven't read) is choosing a toy example, perhaps for pedagogic clarity. Extending that example to real projects without applying a little common sense adjustment may be inappropriate.
精彩评论