Search code examples
unit-testingtestingtddliferayliferay-6

Test Driven Development with Liferay


I am new to Liferay. Can anyone help guide me as to how to follow Test Driven Development with liferay.

Can anyone provide guidelines how to write tests and execute them using eclispe IDE for developing portlets?


Solution

  • Portlets are inherently UI centric and you'll have the same problems as with almost all UI layer code to develop them testdriven. I personally rather like to develop the UI with the user acceptance in mind, keep it as shallow as possible and test the hell out of the underlying business logic, leaving the UI wiring to code review instead of automated tests.

    I know that this leaves a hole in terms of test coverage, but I feel that most of the UI layer tests are 80% setup, 5% actual assertions (max) and 15% teardown code. IMHO this does not make up a valuable test case.

    As you're specifically asking about Test Driven Development: Keep in mind that TDD is primarily a design technique. The resulting tests are very welcome collateral, but the main purpose is to design the software under test. (TDD software inherently looks different compared to paper-designed or other non-TDD styles). When a big part of the architecture and design is imposed by the UI framework, this leaves not enough to "design" with TDD - so I'd rather design the user interaction and make it compelling (while keeping it as thin as possible)

    With that, feel free to add integration tests on top of your UI - typically you wouldn't use JUnit for that, and the execution time might be longer than your unit tests', but it will be well worth having that type of tests on top of your UI. Just don't expect too much insight into your UI layer from designing it from the test side. Keep this for your business layer (and the various utility style code bits that you use on the UI layer), but not for the pure wiring of business layer to user interaction.