Ability to avoid repeated load of application context in spring TestContext via DependencyInjectionTestExecutionListener

StackOverflow https://stackoverflow.com/questions/11202535

  •  17-06-2021
  •  | 
  •  

Pregunta

Lets say I have a test class called ServiceTest with three test methods test1, test2 and test3. All three methods use some resources which are provided by spring. In the current state of affairs, if there is a problem with the loading of the spring context, the context load is retried for each test method. Is there a way that I can have it aborted on the first failure itself with existing hook-ins? There might be good reasons behind it - but I fail to appreciate it. Any pointers would be helpful. The real problem is that the context load takes a few minutes and is useless to keep reattempting to load context if it has already failed for the first time and only seeks to prolong the time that the CI engine takes to report failures.

I was thinking of proposing a patch to spring guys that can maintain an attempt map in org.springframework.test.context.TestContext which can be used to track attempts made and refrain from trying over and over again. Thoughts?

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:com/kilo/spring/test-context.xml" })
public class ServiceTest {

@Resource(name = "fibonacciService")
private FibonacciService fibonacciService;

@Test
public void test1() {
    long fibonacci = fibonacciService.getFibonacci(5);
}

@Test
public void test2() {
    long fibonacci = fibonacciService.getFibonacci(4);
}

@Test
public void test3() {
    long fibonacci = fibonacciService.getFibonacci(6);
}
¿Fue útil?

Solución

No, there is currently no way to have ApplicationContext loading aborted on the first failure with existing hook-ins.

Feel free to create a JIRA issue against the SPR project and the Test component with your suggestions.

Regards,

Sam (author of the Spring TestContext Framework)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top