Gasper is a very simple integration testing JUnit harness for java -jar
servers like WildFly Swarm and Spring Boot.
Gasper provides a simple to use JUnit TestRule
that can be used to build integration tests with simple apps, like REST micro-services. You can configure Gasper easily with a builder interface. Gasper will start the application before test class and stop it after tests completes.
Gasper supports currently only Maven. The pom.xml
file is used to read project configuration achieving zero configuration operation.
Gasper utilize your packaged application. It It means it should be used in integration tests that run after application is being packaged by build tool (Maven). Add this code to your pom.xml
file (if you didn't done that before):
<build>
[..]
<plugins>
[..]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
[..]
</plugins>
[..]
</build>
Place your integration tests in classes that ends with *IT
or *ITest
.
@ClassRule
public static Gasper gasper = Gasper.configurations()
.wildflySwarm()
.build();
@ClassRule
public static Gasper gasper = Gasper.configurations()
.springBoot()
.build();
Before running GasperBuilder.build()
method, you can reconfigure those default configurations to your needs.
Gasper is best to use with libraries like Unirest for fetching data and asserting HTTP/S statuses and JSON Assert to validate correctness of JSON output for REST services.
@Test
public void testGetRoot() throws UnirestException {
// given
String address = gasper.getAddress(); // Address to deployed app, running live on random port
String expectedMessage = "WildFly Swarm!";
// when
HttpResponse<String> response = Unirest.get(address).asString();
// then
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getBody()).field("hello").isEqualTo(expectedMessage); // JSON Assert
}
To configure Gasper use GasperBuilder
interface, for ex.:
private final int port = 11909;
private final String webContext = "/test";
private final String systemPropertyForPort = "swarm.http.port";
@ClassRule
public static Gasper gasper = Gasper.configure()
.silentGasperMessages()
.usingSystemPropertyForPort(systemPropertyForPort)
.withSystemProperty("swarm.context.path", webContext)
.withSystemProperty(systemPropertyForPort, String.valueOf(port))
.withJVMOptions("-server", "-Xms1G", "-Xmx1G", "-XX:+UseConcMarkSweepGC")
.withMaxStartupTime(100)
.withMaxDeploymentTime(20)
.withEnvironmentVariable("jdbc.password", "S3CreT!1")
.withTestApplicationLoggingOnConsole()
.usingPomFile(Paths.get("pom.xml"))
.withArtifactPackaging("jar")
.waitForWebContext(webContext)
.withArtifactClassifier("swarm")
.usingWebContextChecker(GasperBuilderTest::checkContext)
.withPort(port)
.build();
<dependency>
<groupId>pl.wavesoftware</groupId>
<artifactId>gasper</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
Contributions are welcome!
To contribute, follow the standard git flow of:
- Fork it
- Create your feature branch (
git checkout -b feature/my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/my-new-feature
) - Create new Pull Request
Even if you can't contribute code, if you have an idea for an improvement please open an issue.
- Java 8
- Maven 3
1.0.0
- codename: SkyMango- First publicly available release