我试图升级由两个测试片(在我的情况下为@JsonTest和@JdbcTest,中间是脆脆的测试代码)制成的美味三明治,为其添加了Spring Boot 2.1风味。但似乎并没有太大的成功。我无法使用许多@ ... Test注释测试,因为它们现在各自带有自己的XxxTestContextBootstrapper。当他们都使用相同的SpringBootTestContextBootstrapper时,它可以正常工作。
@RunWith(SpringRunner.class)
@JdbcTest
@JsonTest
public class Test {
@Test
public void test() { System.out.printn("Hello, World !"); }
}
我从BootstrapUtils得到的错误是llegalStateStateException: 配置错误:为测试类找到了@BootstrapWith的多个声明
我了解我在这里可能做错了什么,但是有一种简单的方法可以同时加载Json和Jdbc上下文吗?
答案 0 :(得分:4)
测试切片注释并不是真正按照这样构成的。恐怕您的代码只能在Spring Boot 2.0中起作用。
您真的只需要选择一个@...Test
注释,然后将其与一个或多个@AutoConfigure...
注释组合即可。对于上面的示例,我会写:
@RunWith(SpringRunner.class)
@JdbcTest
@AutoConfigureJson
@AutoConfigureJsonTesters
public class Test {
@Test
public void test() {
System.out.println("Hello, World !");
}
}