Interface MongoDbClassExtension

  • All Superinterfaces:
    org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.Extension, MongoDb
    All Known Implementing Classes:
    StartLocalMongoDbClassExtension, UseExistingMongoDbClassExtension

    public interface MongoDbClassExtension
    extends MongoDb, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback
    JUnit 5 Extension for running a MongoDB instance alongside the (integration) tests. Can be configured with custom user credentials and database name. Use MongoDb.getHosts() to retrieve the host to connect to.

    Example usage:

     @RegisterExtension
     @Order(0)
     static final MongoDbClassExtension MONGO_DB_EXTENSION = MongoDbClassExtension
         .builder()
         .withDatabase("my_db")
         .withUsername("my_user")
         .withPassword("my_s3cr3t")
         .build();
     

    Normally a MongoDb is started on demand. For connecting to an already running MongoDb set the environment variable TEST_MONGODB_CONNECTION_STRING.