public class JunitServerRunner
extends org.junit.runners.BlockJUnit4ClassRunner
JunitServerRunner class with the JUnit RunWith annotation:
@RunWith(JunitServerRunner.class)
public class MyTest {
// Get the server
@TestHttpServer
private static EmbeddedServer server;
// Get a client to query embedded server
@TestHttpServer
private HttpClient client;
@Test
public void testGET() {
HttpResponse rsp = client.prepareGet("/path")
.acceptJson()
.execute();
Assert.assertTrue(rsp.status() == 200);
}
}
ServerRule or the runner?ServerRule| Modifier | Constructor and Description |
|---|---|
|
JunitServerRunner(Class<?> klass)
Create runner starting an embedded server.
|
protected |
JunitServerRunner(Class<?> klass,
EmbeddedServer<?> server)
Create runner with given embedded server.
|
| Modifier and Type | Method and Description |
|---|---|
protected List<org.junit.rules.TestRule> |
classRules() |
protected List<org.junit.rules.TestRule> |
getTestRules(Object target) |
collectInitializationErrors, computeTestMethods, createTest, describeChild, getChildren, isIgnored, methodBlock, methodInvoker, possiblyExpectingExceptions, rules, runChild, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor, withAfters, withBefores, withPotentialTimeoutpublic JunitServerRunner(Class<?> klass) throws org.junit.runners.model.InitializationError
junit-servers-jetty or junit-servers-tomcat dependency must
be added to the classpath. In case of a conflict (i.e if both dependency are available in the
classpath), junit-servers-jetty will be used.klass - Running class.org.junit.runners.model.InitializationError - If an error occurred while starting embedded server.protected JunitServerRunner(Class<?> klass, EmbeddedServer<?> server) throws org.junit.runners.model.InitializationError
klass - Running class.server - The embedded server to use.org.junit.runners.model.InitializationError - If an error occurred while starting embedded server.protected List<org.junit.rules.TestRule> classRules()
classRules in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>Copyright © 2019. All rights reserved.