testcontainers | Selenide + TestContainers sample project | Continuous Deployment library

 by   selenide-examples Java Version: Current License: MIT

kandi X-RAY | testcontainers Summary

kandi X-RAY | testcontainers Summary

testcontainers is a Java library typically used in Devops, Continuous Deployment, Spring Boot, Docker, Selenium applications. testcontainers has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can download it from GitHub.

This is a sample project showing how to run tests in Docker with help of TestContainer library.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              testcontainers has a highly active ecosystem.
              It has 30 star(s) with 15 fork(s). There are 9 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 0 open issues and 2 have been closed. On average issues are closed in 9 days. There are no pull requests.
              It has a positive sentiment in the developer community.
              The latest version of testcontainers is current.

            kandi-Quality Quality

              testcontainers has 0 bugs and 9 code smells.

            kandi-Security Security

              testcontainers has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              testcontainers code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              testcontainers is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              testcontainers releases are not available. You will need to build from source code and install.
              Build file is available. You can build the component from source.
              testcontainers saves you 89 person hours of effort in developing the same functionality from scratch.
              It has 232 lines of code, 15 functions and 5 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of testcontainers
            Get all kandi verified functions for this library.

            testcontainers Key Features

            No Key Features are available at this moment for testcontainers.

            testcontainers Examples and Code Snippets

            No Code Snippets are available at this moment for testcontainers.

            Community Discussions

            QUESTION

            How can I reuse containers during integration tests with quarkus?
            Asked 2022-Apr-01 at 15:30

            I currently have a few integration tests that are running fine, however I'm using the annotation @QuarkusTestResource to launch containers via testcontainers before quarkus is launched and I adapt my properties to the random test container port by overriding the start method of my container class extending QuarkusTestResourceLifecycleManager.

            To optimize a little bit I'd like for example to reuse my container that launches kafka since it takes 6-8 seconds to start it and reuse it for several of my integration tests. I've not been able to do so. Since Quarkus manages the lifecycle every times it stops, between every test class, it also stops every container. I tried mixing singleton containers from testcontainers with the Quarkus test resources but it doesn't work. Here's a snippet of the start of one of my integration test class :

            ...

            ANSWER

            Answered 2022-Apr-01 at 15:30

            You can use the experimental reusable mode for your container via .withReuse(true).

            Please note that in order for this to work you need to:

            • set the testcontainers.reuse.enable=true property in the ~/.testcontainers.properties file
            • NOT call .close() (which programmatically stops the container in any way)

            Once you've setup everything accordingly your container should

            • not be stopped/garbage collected at the end of the test run anymore
            • be picked up again at the next test run - avoiding a new container start

            Please note that all runtime modifications (configuration, data, topics etc.) will still be there at the next test run. You need to take suitable measures to avoid non-deterministic tests - like using different / random topic names for each test run.

            Also note that you'll need to manually stop/delete the container when you're done with it. Testcontainers will not remove the container for you anymore.

            You can also read this article that describes how to do it from spring for inspiration: Reuse Containers With Testcontainers for Fast Integration Test

            Source https://stackoverflow.com/questions/71680113

            QUESTION

            Testcontainers with Podman in Java tests
            Asked 2022-Mar-28 at 17:00

            Is it possible to use Testcontainers with Podman in Java tests? As of March 2022 Testcontainers library doesn't detect an installed Podman as a valid Docker environment.

            Can Podman be a Docker replacement on both MacOS with Apple silicon (local development environment) and Linux x86_64 (CI/CD environment)?

            ...

            ANSWER

            Answered 2022-Mar-28 at 17:00

            It is possible to use Podman with Testcontainers in Java projects, that use Gradle on Linux and MacOS (both x86_64 and Apple silicon).

            Prerequisites Enable the Podman service

            Testcontainers library communicates with Podman using socket file.

            Linux

            Start Podman service for a regular user (rootless) and make it listen to a socket:

            Source https://stackoverflow.com/questions/71549856

            QUESTION

            Don't want to use DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD with TestContainers
            Asked 2022-Mar-28 at 08:20

            I am doing an integration test with testcontainers and spring-boot and I am having an issue while initializing the scripts. I have 2 scripts: schema.sql and data.sql.

            When I use DirtiesContext.ClassMode.AFTER_EACH_TEST_METHODit works fine, but it is not a good idea to rerun a new container after each test. Of course that make the tests very slow.

            At the other hand when I use DirtiesContext.ClassMode.AFTER_CLASS I have this exception:

            org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of class path resource [sql/mariadb/schema.sql]: DROP TABLE IF EXISTS client; nested exception is java.sql.SQLIntegrityConstraintViolationException: (conn=4) Cannot delete or update a parent row: a foreign key constraint fails at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:282) ~[spring-jdbc-5.3.13.jar:5.3.13] at ... Caused by: java.sql.SQLIntegrityConstraintViolationException: (conn=4) Cannot delete or update a parent row: a foreign key constraint fails ... Caused by: org.mariadb.jdbc.internal.util.exceptions.MariaDbSqlException: Cannot delete or update a parent row: a foreign key constraint fails

            The base class:

            ...

            ANSWER

            Answered 2022-Mar-28 at 08:20

            The @Sql will be executed, per default, BEFORE_TEST_METHOD. So this is run before each test method. In other words, before any test is run, that SQL is executed. But of course, by re-using the same database for multiple tests, this can run into an error, if the sql script isn't "idempotent", in other words, if the sql script cannot be applied safely twice to the same database.

            To make it work, there are multiple possibilities, for example:

            1. adding one for the AFTER_TEST_METHOD to cleanup. This then would basically remove all the stuff that was added by this test (including the things added by the @Sql before). This way, your db is "cleaned up" after each test run and every run can apply the same sql script again safely.

            2. Or make it safe to be executed multiple times. This depends on the scripts, but if you can write the SQL in a way that allows you to run it twice without error, this would also work.

            3. Without using @Sql, you could also configure a DatabasePopulator bean in your test config. This way, your SQL code would only run ONCE, when the whole application context is created.

            4. You could also try using @Transactional on your test, which would make Spring wrap a transaction around your test execution and roll it back afterwards. Unfortunately I have currently no clue how nice this plays with @Sql, might work, might not, but I would give it a 75% chance of working. And of course, it has some implications (nothing is actually finally written to the DB and if you are using transactions inside your code, there might be complications).

            All of these methods would solve your problem, probably.

            Source https://stackoverflow.com/questions/71625930

            QUESTION

            Quarkus: Overwrite DEV profile config with empty values for Postgres properties
            Asked 2022-Mar-11 at 10:48

            I'm using Quarkus (2.7.3.Final) with Postgres (quarkus-jdbc-postgresql).

            And I really like Quarkus' approach that if you configure no username, password and url for your datasource it will try to start a testcontainer and emulate the database, when you start the app in development mode.

            So for example if you define this in your application.yml (or application.properties), Quarkus will start a Postgres testcontainer for you, when you start the app with ./mvnw clean quarkus:dev:

            ...

            ANSWER

            Answered 2022-Mar-04 at 23:05

            Following Quarkus' official documentation,

            If a profile does not define a value for a specific attribute, the default (no profile) value is used

            This behaviour will be useful in many cases, but in yours might lead to the inability to override properties once defined in the default profile back to their empty state.

            I would suggest you to swap your profiles around i.e. treat the null-valued dev configuration as a default and provide meaningful non-null prod values in an overriding profile.

            If you are worried that dev values might be used this way accidentally in prod environment, remember that Quarkus is going to use prod profile by default if not told otherwise.

            Source https://stackoverflow.com/questions/71354355

            QUESTION

            Quarkus and Selenium TestContainer- how to trigger recording
            Asked 2022-Mar-04 at 09:06

            I am having trouble getting Selenium TestContainers to record the tests for me.

            I am using TestContainers in Quarkus. The Quarkus way to deal with setting up test resources in a QuarkusTestResourceLifecycleManager class, as such:

            ...

            ANSWER

            Answered 2022-Mar-04 at 09:06

            Best-case I would love to be able to trigger recording in a standard junit @AfterEach method, but the arguments required (TestDescription description, Optional throwable) aren't available...

            This is what I would recommend for more advanced framework integrations that don't work OOTB. You should be able instatiate a TestDescription for your use case e.g., from an anonymous class (it is used to infer the recording's file name).

            Source https://stackoverflow.com/questions/71339222

            QUESTION

            Unable to connect to Ryuk?
            Asked 2022-Feb-24 at 16:03

            Hi I am trying to spin up a test container from my unit test class.

            from my test class i am using the following

            ...

            ANSWER

            Answered 2022-Feb-24 at 16:03

            By accident stumbled accross here: I had the same issue when I was not running the docker engine and the service. Have you docker installed and is the service running?

            Source https://stackoverflow.com/questions/70700101

            QUESTION

            GitHub Actions: How can I cache the Docker images for Testcontainers?
            Asked 2022-Feb-19 at 08:28

            I execute some tests in GitHub Actions using Testcontainers.

            Testcontainers pulls the images which are used in my tests. Unfortunately the images are pulled again at every build.

            How can I cache the images in GitHub Actions?

            ...

            ANSWER

            Answered 2022-Feb-19 at 08:28

            There's no official support from GitHub Actions (yet) to support caching pulled Docker images (see this and this issue).

            What you can do is to pull the Docker images, save them as a .tar archive and store them in a folder for the GitHub Actions cache action to pick it up.

            A sample workflow can look like the following:

            Source https://stackoverflow.com/questions/71180135

            QUESTION

            Getting Liquibase to run an SQL script on start up with SpringBoot Kotlin
            Asked 2022-Feb-19 at 00:59

            I'm having trouble getting liquibase to execute my sql script in my SpringBoot Kotlin appllication.

            Here is my build.gradle.kts

            ...

            ANSWER

            Answered 2022-Feb-19 at 00:59

            While running your setup with debug logs enabled, I've noticed that auto-configuration for Liquibase did not work, as some criteria was not met.

            Source https://stackoverflow.com/questions/71130570

            QUESTION

            How to reuse a `testcontainers` container with two different drivers?
            Asked 2022-Feb-14 at 15:05

            I'm using both r2dbc and Liquibase in the same application. However, Liquibase is not able to run migrations using r2dbc so I need to use a separate jdbc driver just for it.

            I followed the solution here, and used testcontainers for testing, so my application-test.yaml looks exactly like this:

            ...

            ANSWER

            Answered 2022-Feb-14 at 15:05

            When you use Testcontainers' JDBC support, which you configure by adding tc in the jdbc url, the lifecycle of the container is managed automatically. Since you have two different urls instrumented like that, you get 2 containers.

            Instead you can choose a different way to manage the lifecycle that gives you more control.

            You can either do it yourself by creating a containers instances and calling start()/stop() or for example use JUnit integration which will correspond containers lifecycle with the tests lifecycle.

            For example for JUnit5, you mark you class with @Testcontainers and the fields with @Container, something like:

            Source https://stackoverflow.com/questions/71103813

            QUESTION

            Gitlab-ci image with docker and java/gradle
            Asked 2022-Feb-14 at 09:22

            I'm including an integration test into my application using library "https://www.testcontainers.org/".

            This library need a docker environment to run "gradlew test" command.

            How would you use a docker image (which include docker and Gradle) in a gitlab-ci.yml?

            ...

            ANSWER

            Answered 2022-Feb-14 at 09:22

            That looks like what Christos Sotiriou described in "Your Private CI/CD using self-hosted GitLab and Docker" in 2020.

            It involves a GitLab runner:

            A GitLab runner has many modes it can operate, which represent how the build will be performed. Among other modes, there is support for spawning Kubernetes pods, or Docker containers to perform builds.

            For the sake of simplicity, we will use the plain docker mode, which will spawn a new container with an image of your choice (determined by your Dockerfile)

            Run the following to your terminal:

            Source https://stackoverflow.com/questions/71108861

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install testcontainers

            You can download it from GitHub.
            You can use testcontainers like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the testcontainers component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/selenide-examples/testcontainers.git

          • CLI

            gh repo clone selenide-examples/testcontainers

          • sshUrl

            git@github.com:selenide-examples/testcontainers.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link