Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does TDD apply well when developing an UI?

What are your opinions and experiences regarding using TDD when developing an user interface?

I have been pondering about this question for some time now and just can't reach a final decision. We are about to start a Silverlight project, and I checked out the Microsoft Silverlight Unit Test Framework with TDD in mind, but I am not sure how to apply the approach to UI-development in general - or to Silverlight in particular.

EDIT: The question is about if it is practical thing to use TDD for UI-development, not about how to do separation of concerns.

like image 951
JacobE Avatar asked Dec 12 '08 13:12

JacobE


People also ask

Does TDD improve design?

Definitely, TDD leads to better design, TDD leads to better code quality, TDD leads to better maintainability of code.

Is TDD a good approach?

TDD makes refactoring and maintenance much easier. As all functionality is covered by tests, any change in code that might introduce an error is easily detectable, since unit tests begin to fail. This way, developers can be sure that when they revisit prior version code, changes can be made with confidence.


2 Answers

Trying to test the exact placement of UI components is pointless. First because layout is subjective and should be "tested" by humans. Second, because as the UI changes you'll be constantly rewriting your tests.

Similarly, don't test the GUI components themselves, unless you're writing new components. Trust the framework to do its job.

Instead, you should be testing the behavior that underlies those components: the controllers and models that make up your application. Using TDD in this case drives you toward a separation of concerns, so that your model is truly a data management object and your controller is truly a behavior object, and neither of them are tightly coupled to the UI.

like image 68
kdgregory Avatar answered Oct 08 '22 05:10

kdgregory


I look at TDD from a UI perspective more from the bare acceptance criteria for the UI to pass. In some circles, this is being labeled as ATDD or Acceptance Test Driven Development.

Biggest over-engineering I have found in using TDD for UIs is when I got all excited about using automated tests to test look and feel issues. My advice: don't! Focus on testing the behavior: this click produces these events, this data is available or displayed (but not how it's displayed). Look and Feel really is the domain of your independent testing team.

The key is to focus your energy on "High Value Add" activities. Automated style tests are more of a debt (keeping them up to date) than a value add.

like image 37
bangroot Avatar answered Oct 08 '22 03:10

bangroot