情况:
- 我在用
Spring Cloud
同Spring Boot
在微服务中,微服务正在加载数据库配置信息以配置连接。 - 我创建了一个测试来使用其他接口
Swagger
用于文档。 - 我想禁用数据库配置的加载,因为没有必要。
这是代码:
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {Application.class, Swagger2MarkupTest.class}, loader = SpringApplicationContextLoader.class)
@ActiveProfiles("test")
public class Swagger2MarkupTest {
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Autowired
protected Environment env;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
}
@Test
public void convertSwaggerToAsciiDoc() throws Exception {
this.mockMvc.perform(get("/v2/api-docs").accept(MediaType.APPLICATION_JSON))
.andDo(Swagger2MarkupResultHandler.outputDirectory("target/docs/asciidoc/generated")
.withExamples("target/docs/asciidoc/generated/exampless").build())
.andExpect(status().isOk());
}
}
如何在不加载数据库配置的情况下运行测试? 这可能吗?