JSFUnitPerformanceAnalysis

Introduction

JSFUnit provides a JSFTimer class that tracks the time spent in each phase of the JSF lifecycle. It also allows you to see the total lifecycle time. The JSFTimer remains accurate, even when JSF lifecycle phases are skipped. And, it can be used in your application code as well as in JSFUnit tests.

Enabling the JSFTimer

The JSFTimer is disabled by default. To enable it, you need to add the JSFTimerPhaseListener to your test setup. You can add this in your application's faces-config.xml, but it is cleaner to do it in a separate file so that you don't have to modify the application. JSFUnit only requires modification to web.xml. So you can add a declaration for the new file there. To configure it this way, add this to your "jsfunified" web.xml:

Geting a reference to JSFTimer

You just call the static getTimer() method to get a timer for the previous (or current) request. If you are using the timer from within the JSF lifecycle, it will return accurate statistics for time spent up to the last completed phase.

JSFTimer timer = JSFTimer.getTimer();

Using the JSFTimer in a JSFUnit Test

A typical test case is to make sure that JSF request processing doesn't fall below a certain threshold in regression tests. A new JSFTimer instance is created for each request, so you need to call getTimer() after each submit. Note that total time is returned in milliseconds.

Using the JSFTimer outside of JSFUnit Tests

The JSFTimer can be used outside of JSFUnit tests. You just need to put the JSFUnit core jar in your WEB-INF/lib directory and add the phase-listener declaration as shown above. When using the JSFTimer in this way, you would reference the JSFTimer from your application code instead of your tests.