`@DataMongoTest` is similar to `@DataJpaTest` but for Spring Data MongoDB tests.
By default it will configure an in-memory Mongod if `de.flapdoodle.embed:de.flapdoodle.embed.mongo`
is available, configure a `MongoTemplate`, scan for `@Document` classes and
configure Spring Data MongoDB repositories. Regular `@Component` beans will not
be loaded into the `ApplicationContext`:
`@DataMongoTest` can be used if you want to test MongoDB applications. By default, it will
configure an in-memory embedded MongoDB (if available), configure a `MongoTemplate`, scan
for `@Document` classes and configure Spring Data MongoDB repositories. Regular
`@Component` beans will not be loaded into the `ApplicationContext`:
[source,java,indent=0]
----
...
...
@@ -5704,18 +5703,30 @@ be loaded into the `ApplicationContext`:
@RunWith(SpringRunner.class)
@DataMongoTest
public class ExampleDataMongoTests {
@Autowired
private MongoTemplate mongoTemplate;
// ...Your autowired Mongo repositories
//
}
----
The If you want to use `@DataMongoTest` but not the embedded Mongod even if you have `de.flapdoodle.embed:de.flapdoodle.embed.mongo` on the class path, exclude its auto-configuration like so:
In-memory embedded MongoDB generally works well for tests since it is fast and doesn't
require any developer installation. If, however, you prefer to run tests against a real
MongoDB server you should exclude the embedded mongodb auto-configuration: