To start the service, I know one uses new MyService().run(args)
. How to stop it?
I need to start and stop programmatically for setUp()
and tearDown()
in my tests.
You can start the service in new thread, once the test ends the service will shutdown automatically.
However starting in dropwizard 0.6.2 the dropwizard-testing module contains a junit rule exactly for this use case (see here).
Usage of this rule will look something like this:
Class MyTest {
@ClassRule
public static TestRule testRule = new DropwizardServiceRule<MyConfiguration>(MyService.class,
Resources.getResource("service.yml").getPath()));
@Test
public void someTest(){
....