tomcat-test

JUnit rule for running tomcat in tests.

License

License

Categories

Categories

Tomcat Container Application Servers
GroupId

GroupId

io.meles.testing
ArtifactId

ArtifactId

tomcat-test
Last Version

Last Version

0.5
Release Date

Release Date

Type

Type

jar
Description

Description

tomcat-test
JUnit rule for running tomcat in tests.
Project URL

Project URL

https://github.com/neilg/tomcat-test
Source Code Management

Source Code Management

https://github.com/neilg/tomcat-test

Download tomcat-test

How to add to project

<!-- https://jarcasting.com/artifacts/io.meles.testing/tomcat-test/ -->
<dependency>
    <groupId>io.meles.testing</groupId>
    <artifactId>tomcat-test</artifactId>
    <version>0.5</version>
</dependency>
// https://jarcasting.com/artifacts/io.meles.testing/tomcat-test/
implementation 'io.meles.testing:tomcat-test:0.5'
// https://jarcasting.com/artifacts/io.meles.testing/tomcat-test/
implementation ("io.meles.testing:tomcat-test:0.5")
'io.meles.testing:tomcat-test:jar:0.5'
<dependency org="io.meles.testing" name="tomcat-test" rev="0.5">
  <artifact name="tomcat-test" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.meles.testing', module='tomcat-test', version='0.5')
)
libraryDependencies += "io.meles.testing" % "tomcat-test" % "0.5"
[io.meles.testing/tomcat-test "0.5"]

Dependencies

compile (2)

Group / Artifact Type Version
junit : junit jar 4.11
org.apache.tomcat.embed : tomcat-embed-core jar 7.0.52

runtime (2)

Group / Artifact Type Version
org.apache.tomcat.embed : tomcat-embed-jasper Optional jar 7.0.52
org.apache.tomcat.embed : tomcat-embed-logging-juli jar 7.0.52

test (1)

Group / Artifact Type Version
org.hamcrest : hamcrest-library jar 1.3

Project Modules

There are no modules declared in this project.

Tomcat Test Build Status

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();
    // ...
}

Versions

Version
0.5