I am running integration tests for my API which deals with in-memory LDAP server. Sometimes tests gets executed properly and sometimes not. Why is this happening ?
I have tried optimizing test-cases and reducing count of test-cases. Individually each test is passing successfully.
//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
}
}
These test-cases are failing sometimes even though everything else is fine. Why is this happening ? Is it thread related ? What can be done in this case to run these test-cases properly?