Polish contribution
Closes gh-7600
This commit is contained in:
@@ -5687,11 +5687,10 @@ A list of the auto-configuration that is enabled by `@JdbcTest` can be
|
||||
|
||||
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-mongo-test]]
|
||||
==== Auto-configured Data MongoDB tests
|
||||
`@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:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataMongoTest(excludeAutoConfiguration = EmbeddedMongoAutoConfiguration.class)
|
||||
public class ExampleDataMongoNonEmbeddedTests {
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
A list of the auto-configuration that is enabled by `@DataMongoTest` can be
|
||||
|
||||
Reference in New Issue
Block a user