Class JunitServerRunner
java.lang.Object
org.junit.runner.Runner
org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
org.junit.runners.BlockJUnit4ClassRunner
com.github.mjeanroy.junit.servers.junit4.JunitServerRunner
- All Implemented Interfaces:
org.junit.runner.Describable
,org.junit.runner.manipulation.Filterable
,org.junit.runner.manipulation.Orderable
,org.junit.runner.manipulation.Sortable
public class JunitServerRunner
extends org.junit.runners.BlockJUnit4ClassRunner
Runner that will start and stop embedded server before tests.
This runner will also add some custom rules to inject data to test classes.
Should I use the
The runner should be used, but due to the limitation of JUnit (only one runner can be used), the rule can
be used if you need to use a custom runner.
How to use?
Simply set theJunitServerRunner
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);
}
}
Should I use the ServerRule
or the runner?
The runner should be used, but due to the limitation of JUnit (only one runner can be used), the rule can
be used if you need to use a custom runner.- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionJunitServerRunner
(Class<?> klass) Create runner starting an embedded server.protected
JunitServerRunner
(Class<?> klass, EmbeddedServer<?> server) Create runner with given embedded server. -
Method Summary
Modifier and TypeMethodDescriptionprotected List<org.junit.rules.TestRule>
protected List<org.junit.rules.TestRule>
getTestRules
(Object target) Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner
collectInitializationErrors, computeTestMethods, createTest, createTest, describeChild, getChildren, isIgnored, methodBlock, methodInvoker, possiblyExpectingExceptions, rules, runChild, testName, validateConstructor, validateFields, validateInstanceMethods, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateTestMethods, validateZeroArgConstructor, withAfters, withBefores, withPotentialTimeout
Methods inherited from class org.junit.runners.ParentRunner
childrenInvoker, classBlock, createTestClass, filter, getDescription, getName, getRunnerAnnotations, getTestClass, order, run, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withAfterClasses, withBeforeClasses, withInterruptIsolation
Methods inherited from class org.junit.runner.Runner
testCount
-
Constructor Details
-
JunitServerRunner
Create runner starting an embedded server.
The embedded server implementation is automatically detected using classpath detection, so one ofjunit-servers-jetty
orjunit-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.- Parameters:
klass
- Running class.- Throws:
org.junit.runners.model.InitializationError
- If an error occurred while starting embedded server.
-
JunitServerRunner
protected JunitServerRunner(Class<?> klass, EmbeddedServer<?> server) throws org.junit.runners.model.InitializationError Create runner with given embedded server.- Parameters:
klass
- Running class.server
- The embedded server to use.- Throws:
org.junit.runners.model.InitializationError
- If an error occurred while starting embedded server.
-
-
Method Details
-
classRules
- Overrides:
classRules
in classorg.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
-
getTestRules
- Overrides:
getTestRules
in classorg.junit.runners.BlockJUnit4ClassRunner
-