https://github.com/binout/jaxrs-unit
A library for unit testing of JAX-RS application
https://github.com/binout/jaxrs-unit
java javaee jax-rs jaxrs test
Last synced: about 2 months ago
JSON representation
A library for unit testing of JAX-RS application
- Host: GitHub
- URL: https://github.com/binout/jaxrs-unit
- Owner: binout
- License: apache-2.0
- Created: 2014-05-02T14:07:41.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2017-03-03T12:56:42.000Z (about 9 years ago)
- Last Synced: 2025-07-06T14:17:26.065Z (9 months ago)
- Topics: java, javaee, jax-rs, jaxrs, test
- Language: Java
- Size: 96.7 KB
- Stars: 1
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
README
= jaxrs-unit
:compat-mode:
A library for unit testing of JAX-RS application.
== Description
The goal is to write unit tests without a real JavaEE server.
But tests use real JAX-RS implementation (Jersey or RestEasy) with in-memory containers.
JaxRS Unit provides an API to encapsulate the specific im-memory containers.
== Build status
image:https://travis-ci.org/binout/jaxrs-unit.svg?branch=master["Build Status", link="https://travis-ci.org/binout/jaxrs-unit"]
== Environment
* +java-1.8+
== Build
[source,bash]
----
mvn clean verify
----
== Usage
=== Maven
You have to add api dependency :
[source, xml]
----
io.github.binout
jaxrs-unit-api
${version}
test
----
You have to choose an implementation :
* RestEasy
[source, xml]
----
io.github.binout
jaxrs-unit-resteasy
${version}
test
----
* Jersey
[source, xml]
----
io.github.binout
jaxrs-unit-jersey
${version}
test
----
=== Hello World
Considering a JAX-RS resource :
[source, java]
----
@Path("/hello")
public class HelloResource {
@GET
public String hello() {
return "hello";
}
}
----
You can write a unit test like this :
[source, java]
----
public class HelloTest {
private JaxrsServer server;
@Before
public void init() {
server = JaxrsUnit.newServer(HelloResource.class);
}
@Test
public void should_return_hello() {
JaxrsResource resource = server.resource("/hello");
JaxrsResponse response = resource.get();
assertThat(response.ok()).isTrue();
assertThat(response.content()).isEqualTo("hello");
}
}
----
== TODO
* resource injection