Skip to main content

Tests d'intégration

Les tests d'intégration utilisent TestContainers. Dans le projet Open ENT, les containers de tests suivant sont disponibles dans :

  • PostgreSQL
  • MongoDB
  • Neo4J
  • ElasticSearch
  • Keycloak

Quarkus a un support natif pour Testcontainers, ce qui signifie qu’il détecte automatiquement certains types de conteneurs à partir des configurations ou des annotations que vous utilisez dans vos tests.

Si vous utilisez une base de données ou un service (comme MongoDB, Neo4J) dans un test, Quarkus va démarrer automatiquement un conteneur correspondant à ce service.

Voici un exemple de démarrage pour un test avec MongoDB et Keycloak en container mais en utilisant une installation locale de Neo4J

[org.tes.DockerClientFactory] (build-13) Testcontainers version: 1.20.0
(matchName = "*",matchRegex = ".*",namespace = "i18n") declared on: java.lang.String message(java.lang.String key, java.lang.Object localeAttr)
[QuteProcessor] Ignoring superfluous matching conditions defined on @TemplateExtension(matchName = "*",matchRegex = ".*",namespace = "i18n") declared on: java.lang.String message(java.lang.String key, java.lang.Object localeAttr)
UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
[DockerClientProviderStrategy] Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
[DockerClientProviderStrategy] Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
[org.tes.DockerClientFactory] (build-13) Docker host IP address is localhost
[DockerClientFactory] Docker host IP address is localhost
[org.tes.DockerClientFactory] (build-13) Connected to docker:
Server Version: 27.1.2
API Version: 1.46
Operating System: Ubuntu 22.04.4 LTS
Total Memory: 32022 MB
[PullPolicy] Image pull policy will be performed by: DefaultPullPolicy()
[ImageNameSubstitutor] Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
[DockerClientFactory] Checking the system...
[DockerClientFactory] ✔︎ Docker server version should be at least 1.6.0
[KeycloakDevServicesProcessor] Using Quarkus powered Keycloak distribution
[7] Creating container for image: quay.io/keycloak/keycloak:23.0.7
[1] Creating container for image: testcontainers/ryuk:0.8.1
[4] Creating container for image: docker.io/mongo:4.4
[1] Container testcontainers/ryuk:0.8.1 is starting:
[io.qua.neo.deployment] (build-2) Not starting Dev Services for Neo4j, as the default config points to a reachable address. Be aware that your local database will be used.
[1] Container testcontainers/ryuk:0.8.1 started in PT0.522324963S
[7] Container quay.io/keycloak/keycloak:23.0.7 is starting: 1f3346d3b1db97556300ceb72a463716fe2261914ff31fcb5286970655a43f87
[4] Container docker.io/mongo:4.4 is starting: 2b3b0cc7bfa0206663140176a23839e25d316eecfe0576d43e8fdd8625e273ad
[4] Container docker.io/mongo:4.4 started in PT2.354415554S
[7] Container quay.io/keycloak/keycloak:23.0.7 started in PT24.49291157S
[KeycloakDevServicesProcessor] Dev Services for Keycloak started.

Container de test Neo4J

Avec la solution https://github.com/quarkiverse/quarkus-neo4j utilisée pour gérer la connexion à Neo4J, la base de données Neo4j n'est pas démarrer dans les tests d'intégration si le port 7687 répond à une requete Neo4J Bolt.

Configurer les containers de test

Les containers de test sont activés suivant les variables définies dans le fichier application.properties ou application-test.properties ou bien suivant le profil défini avec l'annotation @TestProfile

Il est également possible d'utiliser la classe

private static final TestHelper test = TestHelper.helper();

pour configurer manuellement le démarrage des containers