How to wait for the server to rise and run the unit test from Jenkins / Hudson

This is a pretty simple question. I am posting this because I could not get a satisfactory answer. First in the background: I have a Jenkins job that builds and deploys a web application on a server. The server takes some time (about 5-10 minutes). I would like to configure the task (or modify the existing one as necessary) to configure the execution of the unit test case, which the application will check. I think about the following approaches. I would like you to confirm or suggest any alternatives:

  • You have an Ant target that is waiting for a fixed time.
  • Have a custom Ant object that binds a URL and checks for an application.

Thanks in advance for your help. -Vadiraj.

+5
source share
1 answer

Waiting for a fixed time raises the problem that the time you choose is either short (build failures) or long (waste of build time). So I think it would be better to check if the application is available.

I did something similar for my Selenium tests. I had to wait until the Selenium Remote Server started. I used the item waitfor. For detailed documentation see here .

Here is a stripped down version of my ant-Target:

<parallel>
  <sequential>
    ... Start web application server ...
  </sequential>
  <sequential>
    <waitfor maxwait="10" maxwaitunit="minute">
      <socket server="localhost" port="8080" />
    </waitfor>
    <junit>
    ...
    </junit>
  </sequential>
</parallel>

If your server is available before deploying the web application, you can try to use the condition httpinstead socketto check the HTTP error code. The conditions are described here .

+6
source

All Articles