My company has a java-based batch application that's not implemented in Java EE which embeds jetty to handle some web service cal开发者_Go百科ls.
Untill now, none of these endpoints had any functional tests(using something like htmlunit), which is clearly a bad thing.
I've been tasked to do this. My definition of success is to have it behave as much as possible like grails and it's functional test plugin or a traditional Java EE would be using maven's failsafe plugin.
The app has a main() method. Internally, everything(like datasources, how jobs fit together, etc) is configured in Spring.
Does anyone have any suggestions on a strategy? Feel free to prompt me for more information.
Look at Spring's TestContext framework. It allows you to create test-specific application context files and has neat integration with JUnit 4 to support JDBC transactions for your database functionality. Basically Spring creates a new transaction, runs your test method, and then rolls the transaction back after you've had a chance to assert that the database changes are correct. You can run integration tests with unmodified DAO code against a live database without any mess to clean up afterwards.
I ended up using Jersey Test(see this SO entry).
精彩评论