Tomcat Test ![Build Status](https://camo.githubusercontent.com/542ee4f12ff156a7b1c5c2d52d8e29689638490e78aca4ad60c8eba685e6a9a5/68747470733a2f2f7472617669732d63692e6f72672f6e65696c672f746f6d6361742d746573742e706e67)
Embed Tomcat in your JUnit tests.
Getting started
If you're using Maven add a dependency on tomcat-test
<dependency>
<groupId>io.meles.testing</groupId>
<artifactId>tomcat-test</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
If you want to use JSPs you also need
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>7.0.52</version>
</dependency>
Then in your test classes
import static io.meles.test.tomcat.config.TomcatBuilder.*
import static io.meles.test.tomcat.config.WebappBuilder.*
import io.meles.test.tomcat.TomcatRule;
@ClassRule
public static TomcatRule tomcat = new TomcatRule(withTomcat()
.run(webapp("dir/containing/webapp").at("/"))
.onPort(9876));
@Test
public void shouldBehaveInSomeManner() {
// ...
}
If you don't want to bind tomcat to a specific port, for instance if you're running your tests on a build server
@ClassRule
public static TomcatRule tomcat = new TomcatRule(withTomcat()
.run(webapp("dir/containing/webapp").at("/"))
.onFreePort());
@Test
public void shouldBehaveInSomeManner() {
int portTomcatIsListeningOn = tomcat.getLocalPort();
// ...
}