spring - 在与内存服务器集成时,如何在 Spring Boot 中执行测试?
问题描述
我正在为处理内存中 LDAP 服务器的 API 运行集成测试。有时测试会正确执行,有时则不会。为什么会这样?
我尝试过优化测试用例并减少测试用例的数量。单独每个测试都成功通过。
//LDAPInMem.java
public class LdapInMem {
{
function startServer()
{
InMemoryDirectoryServer server;
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig();
//some server configuration code
server.startListening();
}
}
//Integration test
import LDAPInMem
public class UserControllerIntegrationTest {
@Autowired
private WebApplicationContext webApplicationContext;
private MockMvc mockMvc;
@Before
public void setup()
{
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
LDAPInMem.startServer();
}
@Test
public void fun1()
{
//some mockMvc testcase which deals with in-memory server
}
@Test
public void fun2()
{
//some mockMvc testcase which deals with in-memory server
}
@Test
public void fun3()
{
//some mockMvc testcase which deals with in-memory server
}
}
即使其他一切都很好,这些测试用例有时也会失败。为什么会这样?它与线程有关吗?在这种情况下可以做些什么来正确运行这些测试用例?
解决方案
推荐阅读
- python - 如何在python中找到无网格数据的梯度?
- networkx - 使用 ipycytoscape(和 networkx)绘制图形
- java - Logback:部署在 tomcat 服务器上的 resteasy java 应用程序中的日志记录问题
- django - 如何更新 Django 中的数据库?
- python - 根据 pandas 中的行值创建新列
- ionic-framework - 如何在移动应用程序中使 Angular Material 的 mat-select 换行?
- javascript - 用于打开/关闭一排复选框的 Google 表格按钮
- javascript - 如何将此数据分组为可过滤
- javascript - 如何使布尔状态设置器可重用
- r - 一个因子内的ggplot构面网格