Collecting test metadata for in-container tests run

docker

#1

Hey

I have a question regarding running tests in a container as described on https://circleci.com/docs/docker/. I really like the idea but i am just wondering if it is any way to run mu unit tests inside container (like mocha/lab tests ) and take advantage of “Collecting test metadata” as described on https://circleci.com/docs/test-metadata ?

The problem i faced that even if i run my mocha/lab tests like:

docker run <my_just_build_image> /bin/sh -c “/app/node_modules/.bin/lab -l -r junit -o test-results.xml -r console -o stdout test/”

than output of the mocha/lab (output of mocha/lab test reporter) will be saved inside docker container so how to make it accessible to circle ci so it can generate a nice output of my tests run ? According to doc i shall put my test results report inside
$CIRCLE_TEST_REPORTS/junit/test-results.xml but as i run my tests inside docker container the test report will be saved on my docker container not on circle ci machine…
I can tweak it by mounting circle ci host volume to my container, like:

docker run --rm -v CIRCLE_TEST_REPORTS/junit:/tmp {DOCKER_REGISTRY}/${CONTAINER1} /bin/sh -c “/app/node_modules/.bin/lab -l -r junit -o /tmp/test-results.xml -r console -o stdout test/”

but i am just wondering if it is a viable option ?


Insights at test case level
#2

I have chosen a slightly different approach:
I was set on using the exact same dockerfile for dev + deploy.
This means I am mounting the hosts current dir as /app (I am also adding . to /app to have the sources when not on the dev host)
The test run inside the container will write test-results.xml, this is visible in /home/ubuntu/ which is the build environment in CircleCI (due to the mount)
Hence i can simply
sudo cp test-results.xml $CIRCLE_TEST_REPORTS/junit
to get them collected.


#3

Hey

As far as i understand your solution, you would replace application source folder of the container (which already have the application code inside) with circleCi hosts folder (with just checkout-out code).
And then you run your tests inside container that actually run against source code stored on host folder, so output of tests will be also saved on host folder
Am i right ?


#4

Hey @jmilkiewicz, how did you make finally ?
As long as I’m not a Docker rockstar, @gr4per suggestion is not very clear to me.


#5

I think i do undestand his approach but i do not see it viable for my case.
Basically what needs to be done is to expose “test results” as described https://circleci.com/docs/1.0/test-metadata/ . It is all simply
The only problem comes when you wanna run your tests NOT against your checkout code on CircleCI host (this is what CircleCI supports by default ) but against your code which is already “packed” within docker image AND expose test results files on host filesystem ($CIRCLE_TEST_REPORTS folder).
What i did is to simply mount host filesystem to docker container and let my test runner tool “write” test results to that mounted folder


#6