File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Effective Unit Testing: Presentation Layer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Effective Unit Testing: Presentation Layer" Watch "Effective Unit Testing: Presentation Layer" New topic

Effective Unit Testing: Presentation Layer

Erron Austin

Joined: May 01, 2007
Posts: 9
I've seen a lot of UI frameworks starting to push unit testing down to the UI layer.

Do you have recommendations about how best to unit test UI code, e.g. GWT, Vaadin, Javascript frameworks?
In our opinion, does testing the UI logic make sense for this layer or should you focus on E2E testing with tools like Selenium?

Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
What I would do depends so much on the actual code base and technologies involved that it's quite difficult to say much in that direction. With that said, and generalizing a bit, I would expect to see some kind of a "pyramid" shape in place where most of the volume would be in low level, isolated unit tests for individual objects or small clusters of objects and the closer to the system's boundaries your tests would get the fewer and fewer of such tests you would have.

For instance, I'd expect a JavaScript-heavy code base to have unit tests for individual "objects" or functions and I'd expect to have a handful of end-to-end tests with Selenium and the like for increasing the team's certainty about not having broken anything in the larger scheme of things. I would most certainly not want to run thousands of Selenium tests to cover all possible combinations of user input on a form checking that the client-side validations work correctly. Instead, I'd like to check that validations in general for that form are invoked and the UI reflects their result.

I don't know much at all about Vaadin (even though it's built by a bunch of Finns – we're not that small a country :wink and I've only been exposed to GWT on one project shortly. It does seem, however, that most web frameworks aren't really all that test-friendly. They might go really far in making integration testing straightforward but at the same time they might make it really difficult to isolate individual objects for unit testing.

There's a guy in Norway called Johannes Brodwall who's been promoting raw Servlets the past couple of years. It may sound like going back to the stone age but he's got a point – web frameworks can very easily become like an octopus that spreads its tentacles throughout your code base. Anyway, I sense that this is going towards an unnecessary (and somewhat off-topic) rant so I'll just stop here...

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: Effective Unit Testing: Presentation Layer
It's not a secret anymore!