JS Ext

Tuesday, January 29, 2013

Testing JSPs

I have been trying to write more automated test cases in my Java projects.  I have unit tests for individual classes.  I have integration tests between classes.  I have also been making use of Hsqldb to have an in-memory database to test the classes against a real database.  I haven't been able to test JSP rendering, however.

Most of the documentation I read online tends to suggest starting an appserver as part of your build.  I feel like this is a terrible idea.  If you use Tomcat, then this idea may work for you.  If you use something else, then this becomes very prohibitive.  There are licensing considerations.  There are problems with managing the configuration.  If I install the war file into a real appserver, it is going to want a real database.  There is no good way to stub that out.  Once you are connecting to a real database, you throw out the repeatable nature of the test.  You also add a significant amount of time to the build process.

What really needs to happen is someone needs to create a servlet engine that works in an embedded manor.  It should work work like JUnit.  You should be able to fake an HTTP request so the testing servlet engine and mock the midtier that the JSPs would call.  It would be great if we could get code coverage for the JSP files as well.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.