1

IntelliJ project has two modules: Spring Data Rest app and client. Both apps are Spring bootable apps. I made a lot of tests at client and now before every test iteration I have to run the rest service manually. Test class looks like that:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {BusinessRepositoryImpl.class})
public class BusinessLogoRepositoryTest {
..
}

Here is the service:

@EnableAutoConfiguration
@ImportResource({
        "classpath:spring/persistenceContext.xml"
})
@Import(DataServiceConfiguration.class)
public class Application {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

So the question is if it's possible somehow to add the context of service to test class and run the service before test's start.

nKognito
  • 6,297
  • 17
  • 77
  • 138
  • See also this question: http://stackoverflow.com/q/9903341/1857897 Make the service classes available to the test methods and simply start the service before the first test (using @BeforeClass and some singleton initializer) and (if you want) terminate the service on clean up. – dedek Jun 03 '15 at 15:03

1 Answers1

0

You can create a TestSuite with 2 methods annotated with @BeforeClass and @AfterClass to start the service before the tests and stop it after the tests are done.

Draft code to visualize :) what I mean is below.

@RunWith(SpringJUnit4ClassRunner.class)
@SuiteClasses({UnitTest1.class, UnitTest2.class, ... })

@EnableAutoConfiguration
@ImportResource({
    "classpath:spring/persistenceContext.xml"
})
@Import(DataServiceConfiguration.class)

public class TestSuite {

    @BeforeClass
    public void start() throws Exception {
        SpringApplication.run(Application.class, args);
    }

    @AfterClass
    public void start() throws Exception {
        SpringApplication.shutdown();
    }
}
Alexander Pranko
  • 1,859
  • 17
  • 20