Friday, June 5, 2009

Help Me Name My Baby

I've got a new baby and I don't know what to name it. It's a new JSF debug/trace/performance tool. If you've ever seen the Facelets or Seam debug page then you've got an idea of what it is. However, this tool goes beyond those to take "state snaps" before and after each phase. And, it keeps all the info from every request and every session, even expired sessions.

Pre-alpha documentation and download is here.

So now you can debug those nasty AJAX components that do four or five JSF requests with every mouse click. You see all the HttpServletRequest data like params, headers, and cookies. And, you can look at the performance data for each request and each phase.

For now, we store this info in memory for you to peruse at your leisure. Later, I'll probably look at other options like saving to a database. That way, it might be a fit tool for production auditing.

So right now you are either thinking this is really cool or really nuts. Judge for yourself, and let me know. And if you have a good name for it please let me know that too. Right now I'm calling it JSFSpy, but I really don't like that name.

There is no dependency on JSFUnit. Installation just requires dropping a single jar into the WEB-INF/lib of your application. But you can do assertions on the collected data from JSFUnit or you can just browse it with the UI. If you want to use the UI, you'll need to put some xhtml files in your web app. Instructions are here.

Here are the screen shots that should tell you exactly what it does. There's more stuff to add like Seam scopes, JSF2 scopes, component tree, and FacesMessages. What do you think so far?


Main screen shows all HttpSessions ever created.



Request view shows all Http/JSF requests for the selected session.


Scoped Data view shows toString() value of each scoped attribute before and after each phase.


HttpServletRequest view shows incoming URL, headers, request params, cookies, etc.


Perf Data View shows which phases completed and how long each one took.

Tuesday, February 24, 2009

JSFUnit goes GA

I'm very happy to report that the JSFUnit 1.0.0.GA release is now out!

JSFUnit is the only end-to-end BlackBox/WhiteBox testing solution for JSF. Your tests run in-container and out-container at the same time. That is, JSFUnit lets your tests submit real HTTP requests using a headless browser. Then it lets you examine all the artifacts inside the container including the FacesContext, Managed Beans, UIComponent tree, FacesMessages, and much more. And since you are running inside the real container you never need a mock object or stub. You never have to worry about constructing a fake test environment.

Most of you reading this blog have heard all that stuff before, so I'll just talk a bit about the GA release. Here are the main changes from the Beta 3 release.
  • The conversion to HtmlUnit is now complete. The old client side API based on HttpUnit is completely gone. Since HtmlUnit is far better at handling javascript, this means that most JSF AJAX libraries will work right out of the box. The notable exception is ICEfaces, and I've been working with ICEfaces team to get support for that as soon as possible.
  • We now have a JSFUnit deployer for JBoss AS5. I blogged about this earlier. This deployer lets you run your JSFUnit tests without making a single change to your WAR. Click here for details.
  • JSF 2.0 support. I know you are wanting to play around with JSF 2.0, right? Now you don't have to give up test-first development while you explore.
  • The last change is a bit of sad news. The two developers who were working on the JSFUnit static analysis tool have moved on to new jobs where they are no longer using JSF. I versioned the code to 1.0 along with everything else, but I do want everyone to be aware that new features and bug fixes for static analysis won't happen until someone else steps up. If you are interested in taking this on let me know. JSF static analysis is really cool stuff and it's a very useful tool.
Lastly, I want to thank everyone who helped make JSFUnit happen. This is a new kind of tool that required a lot experimentation before we got it right. It has taken much longer to get here than I expected. The community feedback has been great and I've gotten tremendous support internally at JBoss/RedHat. So, in no particular order, thanks to Brian, Dennis, Jason, Matt, Shelly, Julien, Kragoth, Wolfgang, Patrick, Dimitris, Farah, Sacha, Kito, Pete, Ed, Ryan, Alexander, Jesper, Neil, Ken, and a bunch of others I've probably forgotten.

So long, and thanks for all the fish,

Stan

Monday, January 5, 2009

JSF 2.0 and the upcoming GA release of JSFUnit

I don't work on JSFUnit full time. A big part of my responsibility at JBoss/Red Hat is to make sure that JSF and Seam integrate nicely with the JBoss Application Server.

So I've been looking at the JSF 2.0 Public Review release. Using JSF 2.0 with JBoss AS 4.2 and AS 5.0 seems to be just a matter of replacing jsf-api.jar and jsf-impl.jar. I'm sure that I'll come across some things that need more/better integration. And when I do, I'll have to implement something new. But for now I'm happy to be able to play with the JSF 2.0 PR release as-is on JBoss AS.

To see how much would run without error, I decided to go ahead and upgrade JSFUnit to work with the new JSF 2.0 API. That required adding methods to JSFUnitFacesContext and JSFUnitExternalContext. There were some other code changes, including a change to the Environment class that detects which version of JSF is running.

Anyhow, I'm happy to report that JSFUnit now works with JSF 2.0. You can download the latest JSFUnit snapshot if you'd like to play with it. The part of the JSFUnit test suite that doesn't run is execution of the applications that use Facelets and Ajax4Jsf/RichFaces together. I've filed a bug on it, so hopefully that problem will be resolved soon. Please leave me feedback on the JSFUnit Forum if you decide to give it a try.

Lastly, I've been asked several times when JSFUnit is going to go GA. There is really nothing stopping me now except that I'd like to fix a few more bugs and maybe add support for IceFaces. Look for a release in mid-February.

So long and thanks for all the fish,

Stan

Sunday, October 12, 2008

JSFUnit experience required

The JSFUnit project has reached a new milestone. This is the first job posting I've seen where JSFUnit experience is required.

http://www.bidtowork.com/2008/10/09/java-test-engineer-with-jsfunit-and-httpunit-experience-odesk/

So long and thanks for all the fish,

Stan

Thursday, October 2, 2008

JSFUnit the Easy Way!!

JSFUnit tests are easy to write and understand. This comes across clearly whenever I talk about it at a conference and I see faces light up. They "get it". However, it's also clear that the hardest part of JSFUnit is getting started. Once you get over that hump, developers really like the tool. But until now, setting up JSFUnit for the first time required quite a bit of work.

Enter the new JSFUnit deployer for JBoss AS 5. Now, here is all you need to do to set up JSFUnit for testing:
  1. Copy jboss-jsfunit-microdeployer.jar to /server/default/deployers
  2. Rename your war with a "-jsfunit" suffix (such as "mywar-jsfunit.war")
  3. Add your test classes to the WAR or put them in /server/default/jsfunitTests
  4. Restart JBoss AS 5 and run your tests.
That's it. In fact, with a simple edit to the deployer's descriptor you can even get rid of step 2.

This is all made possible because of the redesigned microcontainer of JBoss AS 5. You can take an ordinary WAR and add servlets, filters, and classes on the fly as it is being deployed. I've been wanting this kind of functionality for as long as I can remember. It's perfect for adding test tools, fixtures, or monitoring. Before now you had to bundle this stuff with the application - stuff that really doesn't belong in your WAR.

The interesting part is that now instead of thinking of a WAR or EAR as "my application", we can truly think of it as a reuseable deployment unit. It's just another component that can be decorated or combined with other components. While this view provokes a lot of questions (security, name collisions, etc.), the mind reels with the possibilities that this represents.

So long, and thanks for all the fish,

Stan

Friday, August 29, 2008

JSFUnit Beta 3 is out. Seam support and more!

JSFUnit Beta 3 is now released. Special thanks to our new committer Brian Gregory for helping with the conversion from HttpUnit to HtmlUnit as our client side technology (see previous post). Also, the HtmlUnit team has been very helpful with answering questions and providing bug fixes.

Click http://wiki.jboss.org/wiki/JSFUnitBeta3Changes for details on new features. Unlike Beta 2, there are many goodies in this release, including support for Seam conversation scope!

If you are a Beta 2 user it is very important that you click the above link and read about the deprecated APIs that will be removed before GA. The next planned release will be 1.0.0.GA which should be out before the end of the year.

See this page for download information: http://www.jboss.org/jsfunit/downloads.html.
Keep all the valuable feedback coming. It is greatly appreciated!

See you at JSFOne next week.

So long, and thanks for all the fish,

Stan

Friday, August 8, 2008

Another JSFUnit Beta Coming Soon

And why we dumped HttpUnit for HtmlUnit

We will release JSFUnit Beta 3 before the start of JSFOne on Septemeber 4th. If all goes well, it will probably be out a week or so before that.

Originally, I planned to have the GA release out by now. But the opportunity to improve the JSFUnit tool was too great to pass up. That opportunity came in the form of HtmlUnit. HtmlUnit bills itself as "a headless browser". This is exactly what I've been searching for. That is, a way to truly simulate a user interacting with a JSF application - even one that includes AJAX components.

Up until now, JSFUnit used HttpUnit to submit client requests. And HttpUnit is good at that. But HttpUnit is old, and it's mostly a dormant project. It doesn't support the latest DOM specs. And worst of all, its javascript support is dismal. This makes testing JSF/AJAX applications very difficult. In fact, the javascript support was so bad I had to just turn it off. When testing a JSF/AJAX component I would have to simulate the javascript using Java and then formulate the resulting HTTP request myself. It became clear that it would be too hacky and time-consuming to keep doing things that way.

So for JSFUnit Beta 3, I've written a new version of the JSFClientSession class that uses HtmlUnit instead. With HtmlUnit, we can execute javascript and let that javascript submit to the server. No fuss, no muss.

HtmlUnit is still pretty new, so we've found our share of bugs along the way. But unlike HttpUnit, HtmlUnit has an active core of developers who are working closely with the JSFUnit team to fix problems quickly as possible. Thus, we're doing one last beta release instead of the planned GA.

For Beta 3, you can still use the old HttpUnit-based JSFClientSession and things will work fine. This allows our early adopters to migrate their tests to the new client one at a time. But HttpUnit will be completely gone from JSFUnit for GA. So you do need to migrate before then. The new stuff is in its own package called org.jboss.jsfunit.jsfsession. This replaces the old code in org.jboss.jsfunit.facade.

That's all the news for now. So long, and thanks for all the fish.

Stan