Java Soap集成测试只加载被测试的端点,而不是加载所有端点
我有一个问题: 如果只加载我想在集成测试中测试的Enpoint类,而不是加载整个应用程序上下文(不是所有的Enpoint类),那么正确的配置是什么? 现在我有:Java Soap集成测试只加载被测试的端点,而不是加载所有端点,java,spring-boot,soap,spring-test,spring-ws,Java,Spring Boot,Soap,Spring Test,Spring Ws,我有一个问题: 如果只加载我想在集成测试中测试的Enpoint类,而不是加载整个应用程序上下文(不是所有的Enpoint类),那么正确的配置是什么? 现在我有: @RunWith(SpringRunner.class) @SpringBootTest(classes = {WebServiceConfigTest.class}, properties = {"application.address=http://hostname:port/context"}) public class MyEn
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {WebServiceConfigTest.class}, properties = {"application.address=http://hostname:port/context"})
public class MyEndpointTest {
@Autowired
private ApplicationContext applicationContext;
private MockWebServiceClient mockClient;
@Before
public void init() {
mockClient = MockWebServiceClient.createClient(applicationContext);
MockitoAnnotations.initMocks(this);
}
@Test
public void test1(){}
....
}
在WebServiceConfigTest中:
@ComponentScan("mypackages.soap")
@ContextConfiguration(classes = SoapApplication.class)
@MockBean(classes = {MyService.class})
public class WebServiceConfigTest {
}
SoapApplication是:
@ComponentScan({"mypackages"})
@SpringBootApplication
public class SoapApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
public static void main(String[] args) {
SpringApplication.run(SoapApplication.class, args);
}
}
原因是在Soap模块中,我有一个服务模块的依赖项,它也有其他依赖项,等等。
如果我加载整个应用程序上下文,则:
- 或者我需要模拟我在Soap模块中使用的服务的完整列表
- 或者模拟服务模块的底层依赖关系,如数据源、队列等
控制器
类,而不使用
如果您使用嵌入式数据库(例如H2)或嵌入式队列进行测试,我还建议您使用
@SpringBootTest
进行端到端集成测试。经过长时间的搜索和试用,我找到了解决方案。
正如您可以要求REST上的Spring在上下文中只加载一个控制器一样
@WebMvcTest(MyController.class)
和你用肥皂做的一样
@SpringBootTest(classes = {MyEndpoint.class})
它将只加载您想要的端点,您可以模拟您在其中使用的服务,或者您可以一直到存储库,无论您的应用程序业务逻辑在那里做什么。I这对重新启动有效,我使用了它,但对Soap有效吗?
@SpringBootTest(classes = {MyEndpoint.class})