Unit Testing vs UI Testing

  October 09, 2005

If you've got a good set of unit tests, do you even need to do functional testing through the UI? Experienced testers are probably doing a spit-take just hearing the question, but, believe it or not,  I've heard that question recently from a few different people, and I think the question reflects the excitement they have for the benefits of unit testing. There's no doubt, unit tests have finally brought testing to the front-line of development, and they've improved the quality of countless projects. But, do unit tests make other tests unnecessary? Not by a long shot, you'll need more than unit tests for a professional quality application. Here are a few reasons why:

Who's Watching the Watchmen?

Developers are supposed to write their own unit tests to test the code they write. It's a great rule for writing and refactoring code, but it's a bad rule for thorough testing. It's too easy to write the tests with the same mindset used to write the code, and consequently, miss the same problems. Thorough testing requires another set of eyes to fully exercise code without the same prejudices and assumptions as the person who created it.

Unit Tests Don't Test The UI

Most application users spend all of their time interacting with your program through it's UI, it's user interface. Unit tests are back-end tests, they can check that a calculation is correct, but they can't verify that the results display correctly to your user. And what about problems like unreadable color combinations, incorrect icons, or missing or mislabeled fields? You need UI testing to catch those problems. Or, what if the unit tests work perfectly, but someone ignored your clean model-view-controller architecture, just this once, and slipped a quick calculation fix into your display code? It happens, and when it does, a UI test is the best way to find errors in it before your users do.

Unit Tests Don't Like Black-Box Apps

Many companies have mission critical applications that depend on an off-the-shelf component or application without source code. Unit tests need source code to be effective. Once again, UI testing with simulated user actions is needed to work out these black-box applications.

Unit Tests Are For Methods, Not Systems

Finally, unit tests are meant to be small, fast, encapsulated tools to test classes and methods in isolation. They don't test what happens to your application under real-world conditions. How does your app behave under Windows 98, 2000, NT, or XP service pack 1, 2, or 3? What happens to your server when 30 or 300 users access it simultaneously? How about the same test with 5 years of data on 40,000 accounts? You know the answer, functional testing via the user interface is usually the fastest and most effective way to broaden the scope and depth of your testing to include real-world scenarios which integrate all the components of your application system.


Unit tests are fantastic, but development and QA teams need all the tools they can get to catch defects before software is released. Automated UI testing should be a standard part of your team's tool set if you're serious about software quality.