public class JoobyRule
extends org.junit.rules.ExternalResource
Junit rule to run integration tests. You can choose between @ClassRule or @Rule. The next example uses ClassRule:
import org.jooby.test.JoobyRule; public class MyIntegrationTest { @ClassRule private static JoobyRule bootstrap = new JoobyRule(new MyApp()); }
Here one and only one instance will be created, which means the application start before the first test and stop after the last test. Application state is shared between tests.
While with Rule a new application is created per test. If you have N test, then the application will start/stop N times:
import org.jooby.test.JoobyRule; public class MyIntegrationTest { @Rule private static JoobyRule bootstrap = new JoobyRule(new MyApp()); }
You are free to choice the HTTP client of your choice, like Fluent Apache HTTP client, REST Assured, etc..
Here is a full example with REST Assured:
import org.jooby.Jooby;
public class MyApp extends Jooby {
{
get("/", () -> "I'm real");
}
}
import org.jooby.test.JoobyRyle;
public class MyIntegrationTest {
@ClassRule
static JoobyRule bootstrap = new JoobyRule(new MyApp());
@Test
public void integrationTestJustWorks() {
get("/")
.then()
.assertThat()
.body(equalTo("I'm real"));
}
}
Copyright © 2019. All rights reserved.