Micronaut
Micronaut and AWS Webinar
📅 22 November.
⏳10:00 a.m. to 11:30 a.m. CST.
💵 Free.
👨🏫 Yours truly.
The following topics are covered in this webinar:
- Deploying a Micronaut app to AWS Elastic Beanstalk
- Uploading files to AWS S3 from a Micronaut app
- Securing an app with AWS Cognito
- Publishing a Micronaut function to AWS Lambda
- Sending an email from a Micronaut app with AWS SES
- Service discovery with Route 53
- Alexa skill support with Micronaut
Tools
Testcontainers
Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
Testcontainers make the following kinds of tests easier:
Data access layer integration tests: use a containerized instance of a MySQL, PostgreSQL or Oracle database to test your data access layer code for complete compatibility, but without requiring complex setup on developers' machines and safe in the knowledge that your tests will always start with a known DB state. Any other database type that can be containerized can also be used.
Application integration tests: for running your application in a short-lived test mode with dependencies, such as databases, message queues or web servers.
UI/Acceptance tests: use containerized web browsers, compatible with Selenium, for conducting automated UI tests. Each test can get a fresh instance of the browser, with no browser state, plugin variations or automated browser upgrades to worry about. And you get a video recording of each test session, or just each session where tests failed.
We use it with Spock.
Integration Testing with Docker and Testcontainers by Kevin Wittek
Talk by @Kiview, core mantainer, of the Test Containers project.
Specially interesting to hear the thought about the testing pyramid becoming a diamond since integration tests are now faster and easier to write than ever.
Workshop: Groovy Integration Testing with Spock and Docker
This is was my first stop. @Kiview shows how to integrate tests containers with Grails.
Geb tests with WebDriver Containers
Testcontainers can be used to automatically instantiate and manage containers that include web browsers, such as those from SeleniumHQ's docker-selenium project.
Benefits:
- Fully compatible with Selenium 2/Webdriver tests, by providing a RemoteWebDriver instance. - No need to have specific web browsers, or even a desktop environment, installed on test servers. The only dependency is a working Docker installation and your Java JUnit test suite.
- Browsers are always launched from a fixed, clean image. This means no configuration drift from user changes or automatic browser upgrades.
- Compatibility between browser version and the Selenium API is assured: a compatible version of the browser docker images will be automatically selected to match the version of selenium-api-*.jar on the classpath. - Additionally the use of a clean browser prevents leakage of cookies, cached data or other state between tests.
- VNC screen recording: Testcontainers can automatically record video of test runs (optionally capturing just failing tests).
- Creation of browser containers is fast, so it's actually quite feasible to have a totally fresh browser instance for every test.
I am a Geb lover and we have two services with UI and thus with Geb tests. We have not fully embraced it because I have found some issues with getTestHostIpAddress()
.
Instead of doing:
browser.baseUrl = embeddedServer.URL.toString()
I should be able to do:
browser.baseUrl = "http://${webdriverContainer.testHostIpAddress}:${embeddedServer.port}"
But that it is not working for us in Google Cloud Build. But I see myself adding dockerChrome
and dockerFirefox
environments (see next link) soon to my GebConfig.groovy
.
How to use Webdriver Testcontainers with Geb/Spock
@MichaKutz shows how to combine GebConfig
and Test Containers.
Geb's config mechanism uses a Groovy config script (see ConfigSlurper) to create the WebDriver, so it makes sense to create the Testcontainer in that script.
Networking and communicating with containers
Test Containers ships with multiple networking options such as:
- Exposing container ports to the host
- Getting the container IP address
- Exposing host ports to the container.
I've been checking these networking options for my Geb integration and the approach described in the latter will work for me if I don't instantiate the Test Container drivers in GebConfig.
Example of Docker Compose App with Geb UI Tests
A Docker Compose app by @Kiview with UI Tests using Geb and Test Containers.
Comment
We have recently started using Test Containers in the microservices project I am working on. We started by emulating a dependency to Google Bigtable. Today, we have configured our tests to run against MySQL with a Test Container instead of H2.
Sergio del Amo