Using embedded MongoDB in Spring JUnit @WebMvcTest
After banging our heads for a while we found the @AutoConfigureDataMongo
annotation.
import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo;@RunWith(SpringRunner.class)@WebMvcTest(value = SampleController.class, secure = false)@AutoConfigureDataMongopublic class SampleControllerTest {
Just annotate your controller with it and you should see org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongo
logs when running this controller tests.