tôi có một dự án Maven đa mô-đun với 2 ứng dụng xuân BootLàm cách nào để kiểm tra nhiều ứng dụng Khởi động trong một thử nghiệm?
mẹ
- fooApp
- barApp
- kiểm tra
Làm thế nào để thiết lập một thử nghiệm nơi bạn có thể tải các ứng dụng khởi động mùa xuân riêng biệt, mỗi ứng dụng có bối cảnh cấu hình riêng, trong cùng một quá trình.
public abstract class AbstractIntegrationTest {//test module
protected FOO foo;
protected BAR bar;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@IntegrationTest
@Transactional
@SpringApplicationConfiguration(classes = foo.Application.class)
public class FOO {
public MockMvc mockMvc;
@Autowired
public WebApplicationContext wac;
@Before
public void _0_setup() {
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
TestCase.assertNotNull(mockMvc);
}
public void login(String username) {
}
}
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@IntegrationTest
@Transactional
@SpringApplicationConfiguration(classes = bar.Application.class)
public class BAR {
@Autowired
public WebApplicationContext wac;
public MockMvc restMvc;
@Before
public void _0_setup() {
MockitoAnnotations.initMocks(this);
restMvc = MockMvcBuilders.webAppContextSetup(wac).build();
TestCase.assertNotNull(restMvc);
}
public void login(String username) {
}
}
@Before
public void _0_setup() {
foo = new FOO();
bar = new BAR();
}
}
Và một ví dụ của một thử nghiệm hội nhập
public class IntegrationTest extends AbstractIntegrationTest {
@Test
public void login() {
foo.login("foologin");
bar.login("barlogin");
}
}
Kể từ Spring Boot Test 1.5.0, bạn có thể [được cho là] (https://github.com/spring-projects/spring-boot/issues/8000) sử dụng '@ ContextConfiguration' với' @ SpringBootTest'. ..bạn đã thử sử dụng ngữ cảnh con chưa? –