0

I would like to test the resilience of a Spring Bean which it loads the configuration from a YML file.

In a test, I load a corrupt configuration in order to test if the annotation @Validated run in the proper way:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ServiceExample.class})
@Category({Fast.class})
@ActiveProfiles("profileWithBadConfiguration")
public class ServiceExampleTest {

@Test(expected=IllegalStateException.class)
public void test1() {

}

}

When I try to test execute the test "test1", the JUnit file crash before executing the first tests. The idea is to detect the IllegalStateException in a Test.

Anyone knows, how to test it?

Technical links:

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/validation/annotation/Validated.html https://docs.spring.io/spring/docs/4.1.x/spring-framework-reference/html/validation.html

Many thanks in advance

Juan Antonio

jabrena
  • 1,166
  • 3
  • 11
  • 25
  • Why do you want to test the framework? Unless you are loading the context inside the test method it won't work as, as you already noticed, the context won't load because you are loading an invalid file. – M. Deinum Dec 05 '17 at 20:43

1 Answers1

0

Instead of using Springs test annotations, you could load contexts manually inside the test methods. Examples are given in answers to this question: Use different Spring test context configuration for different test methods

tkruse
  • 10,222
  • 7
  • 53
  • 80