Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

I tried to upgrade a yummy sandwich made of two test slices (@JsonTest and @JdbcTest in my case, crunchy test code in between) adding spring boot 2.1 flavour to it. But it seems it was not much of a success. I cannot annotate my tests with many @...Test since they are now each bringing their own XxxTestContextBootstrapper. It used to work when they all used same SpringBootTestContextBootstrapper.

@RunWith(SpringRunner.class)
@JdbcTest
@JsonTest
public class Test {
  @Test
  public void test() { System.out.printn("Hello, World !"); }
}

The error I get from BootstrapUtils is illegalStateException : Configuration error: found multiple declarations of @BootstrapWith for test class

I understand I might be doing something wrong here but is there an easy way I could load both Json and Jdbc contexts ?

like image 901
cactus sauvage Avatar asked Sep 17 '25 16:09

cactus sauvage


1 Answers

Test slice annotations aren't really designed to be composed like that. Your code worked in Spring Boot 2.0 only by luck I'm afraid.

You really need to pick just one @...Test annotation and then combine it with one or more @AutoConfigure... annotations. For the example above, I would write:

@RunWith(SpringRunner.class)
@JdbcTest
@AutoConfigureJson
@AutoConfigureJsonTesters
public class Test {

  @Test
  public void test() { 
    System.out.println("Hello, World !"); 
  }

}
like image 118
Phil Webb Avatar answered Sep 19 '25 08:09

Phil Webb