Tuesday, August 13, 2013

Integration tests with Selenium

Recently, I've been trying to figure out how to improve the quality of my projects decreasing its bug amount. I know that for most of us programmers, the first think that came in mind is unit tests with JUnit. I agree that they are necessary. No doubt that we can get a lot of benefits testing the application business logic, however we do know that implement these kind of tests nowadays on JEE platform is increasingly difficult. This happens not only because of environment dependent JEE features(JPA, CDI, EJBs) but also because of the huge amount of bad coding projects we face every day.

I do agree unit testing still gonna be the most efficient way to garantee the correctness of our algorithms, but to reach this out we have to write test driven programs, decoupling business and infrastructure layers or using some refactoring technics when talking about legacy systems.

Having this scenario in mind, integration tests became even more important in JEE projects. With this kind of tests we can ensure the entire application life cycle of each request the user may dispatch on a real runnable environment without necessity of mocks.

One really nice free tool that can be used to implement automatic integrated tests is Selenium. This tool is capable of automate web browsers interactions. The solutions is composed by Selenium IDE and Selenium Web Browser.

Selenium IDE is is a Firefox plugin where you can not only record browser interactions in order to create tests scripts but also run these scripts.

Selenium Web Driver is a collection of language specific bindings that can be used through an API to run tests scripts with a unit test program. In java we are talking about JUnit test classes that can ben automatic exported from the Selenium IDE original scripts.

At http://docs.seleniumhq.org/ you can find all resources you need to start creating your own integration tests.