Running tests as usual against docker containers or dockerize tests?

前端 未结 3 1142
灰色年华
灰色年华 2021-02-04 06:51

I\'m new to Docker and was reading up on Docker. It\'s a great way to test systems in a self contained and reproducible standardized configuration (when done correctly).

3条回答
  •  臣服心动
    2021-02-04 07:16

    I don't think you'd dockerize the tests themselves as the process that runs the tests.

    For example if you need to run unit tests in php with phpunit, you would dockerize phpunit and use that to run tests against your code, and similarly for any other test framework you use (i.e. testng, junit... etc.)

    Here's an example of the Dockerfile I use to encapsulate Java/Maven/TestNG for a Java test project which includes some selenium tests:

    FROM maven:3-jdk-8
    
    # Selectively add stuff we need
    COPY pom.xml /usr/src/testng/
    
    # Get a clean build immediately after and 'go-offline' to improve subsequent builds
    RUN cd /usr/src/testng && mvn dependency:go-offline
    COPY src /usr/src/testng/src
    WORKDIR /usr/src/testng/
    
    # Additional support files that's needed but not for the build
    COPY supportfiles /usr/src/testng/supportfiles
    
    CMD [ "mvn test" ]
    

提交回复
热议问题