I have the standard Application class which runs a Spring batch ETL:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
with my Junit test doing something like:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class MyServiceTest {
@Autowired
MyService myService;
@Test
public void testInsertions() {
//do stuff with assertions
}
}
My problem is that when I execute the junit test, the application also kicks off the ETL then executes the test. How to prevent the application from running?
I think there are a lot of alternatives and it really depends on what you are trying to achieve.
One of the options would be to run your tests with a specific profile, like
testing
, and configure your ETLs (I'm assuming they are just jobs) to be configured based on some property or specific profile.For example:
Testing class
Job/ETL classes
Hope it helps.