UI testing vs unit testing

haris hamdani picture haris hamdani · Mar 2, 2011 · Viewed 10k times · Source

what is the different purpose of those both? I mean, in which condition I should do each of them?

as for the example condition. if you have the backend server and several front-end webs, which one you'll do?do-unit testing the backend server first or do-UI testing in the web UI first? given the condition, the server and the front-end webs already exist, so it's not an iterative design to build along with (TDD)...

Answer

Péter Török picture Péter Török · Mar 2, 2011

Unit testing aims to test small portions of your code (individual classes / methods) in isolation from the rest of the world.

UI testing may be a different name for system / functional / acceptance testing, where you test the whole system together to ensure it does what it is supposed to do under real life circumstances. (Unless by UI testing you mean usability / look & feel etc. testing, which is typically constrained to details on the UI.)

You need both of these in most of projects, but at different times: unit testing during development (ideally from the very beginning, TDD style), and UI testing somewhat later, once you actually have some complete end-to-end functionality to test.

If you already have the system running, but no tests, practically you have legacy code. Strive to get the best test coverage achievable with the least effort first, which means high level functional tests. Adding unit tests is needed too, but it takes much more effort and starts to pay back later.

Recommended reading: Working Effectively with Legacy Code.