title: What is the best way to run integration tests using a web server?
body: <p>As the title says, I'm interested in the best approaches of testing an application using a Jetty web server, taking in consideration that you don't want to start/stop the test server for each particular test.</p>
  
  <p>As far as I know, these are the solutions:</p>
  
  <ol>
  <li><p>if you use a build tool like Maven or Gradle, you can do it in the <code>*.pom</code> or <code>*.gradle</code> file.</p>
  
  <ul>
  <li>this has the disadvantage that you have to create the test server in a different way that you normally do it in the application.</li>
  </ul></li>
  <li><p>Creating a test suite and using the <code>@BeforeClass</code> and <code>@AfterClass</code> annotations to start/stop the server before/after the test <code>Suite</code>.</p>
  
  <ul>
  <li>disadvantage here is the "ugly" way of specifying the tests to run. You also have to specify that the test which is added to the suite, it shouldn't run outside of the suite(avoid duplicate run of the test). I think Junit is not yet fully equipped for this.</li>
  </ul></li>
  <li><p>Create and start the server in a static way at the beginning of the tests and use the <code>ShutDown</code> mechanism to hook up in the JVM and stop the server automatically when all the tests are completed. This seems to be the best solution because this mechanism is available in Jetty already, but</p>
  
  <ul>
  <li>the disadvantage is that you are not in control of the stopping of the server. It is done actually in a totally different thread, even outside of the building tool(I use Gradle for this)</li>
  </ul></li>
  </ol>