andrey
andrey

Reputation: 125

How to automate build, deploy and test java web application?

For now I have a web java project which builds automatically and deployed to the JBoss by just copying ear archive to server dir (all using Ant).

What I need is a mechanism how to no only automatically deploy application, but also to verify if application deployed successfully and run HttpUnit tests on it.

The problem is how to automatically monitor deployment process to wait for the moment when deployment is finished and only after that run tests. So I want to build, deploy, run tests in "one click" (i use Cruise Control for that).

I would be appreciate for any suggestion about resolving the problem.

Upvotes: 3

Views: 4269

Answers (4)

recampbell
recampbell

Reputation: 1247

Another option is to use the JBoss Server Ant Tasks.

The nice thing about these tasks is that they will block until JBoss is fully started, so there is no polling required. They will also fail if JBoss fails to start in the required timeout, and will attempt to shut JBoss down at the JVM shutdown if you are unable to because of some error. I believe these tasks are used for the JBoss testsuite.

I've also heard good things about Cargo. The benefit of it is that your build scripts are not JBoss specific. I think the JBoss Cargo plugin is maintained by some JBoss guys, as far as I know.

Upvotes: 1

Pascal Thivent
Pascal Thivent

Reputation: 570615

The need here is to start a container and to deploy an application from a build script before to run tests depending on the deployed application. This is a typical need for integration tests, end-to-end / functional tests, ui tests.

The problem is that we can't just "fire and forget" the launch of a container and run the test task/goal. We need to wait for the application to be deployed before to run the tests and this takes some time. To be sure we can run tests when things are ready, the build has to start the container and deploy the application in a blocking way.

This is exactly what Cargo is about. Cargo is a Java API to start/stop your container and deploy your application. It provides the logic described above and can be used from Java, Ant or Maven.

If you are using Maven, the build life cycle already includes something for you with the "integration-test" phase. This phase is typically used for... integration tests and is wrapped by the "pre-integration-test" and "post-integration-test" phases. This is where you would plug Cargo start/stop goals. If you are using Ant, you can use cargo's ant task.

Another option based on the maven is described in the Mavan Jetty Plugin Configuration Guide. The idea is exactly the same as above except that you use the jetty plugin instead of cargo to start jetty during the "pre-integration-test" and stop it during the "post-integration-test".

Upvotes: 6

Karl
Karl

Reputation: 2955

You could consider using hudson build engine: https://hudson.dev.java.net/ to help you fire off events at specific times.

I know hudson can be used to run unit tests and automatic deployment could be achived by calling ant.

Karl

Upvotes: 0

Aaron Digulla
Aaron Digulla

Reputation: 328830

Create a base test class from which all other tests derive. It has to be abstract so the automatic unit test collector doesn't try to run it.

In that class, add this code to setUp():

if (checkIsDeployed) {
    ... run code to verify your app is ready for testing and wait until it is ...
    checkIsDeployed = true;
}

checkIsDeployed must be static.

Upvotes: 1

Related Questions