This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you are using Spring Boot with MongoDB, then a MongoDB connection is required even if you are unit testing a function. | |
Spring creates a connection to mongoDB during start up, because of Autowired beans in your code. This slows down your unit tests, and | |
also means your unit tests require access to the MongoDB server. | |
Here is what you need to do: | |
1. Mock the beans created by org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration: | |
@Bean | |
public MongoDbFactory mongoDbFactory(){ | |
return null; | |
} |