Run NUnit tests using Docker image

Viewed 342

I am trying to use a docker image in a Gitlab pipeline in order to run my tests. I found multiple Docker images on Docker Hub that install the NUnit console on top of Mono, but they all call that console within their entrypoint. Let's take craigvincent/nunit-console for example:

FROM mono:4.4

ENV NUNIT_VERSION 3.4.1

RUN \
    apt-get update && \
    apt-get install -y && \
    apt-get install -y wget && \
    nuget install NUnit.Runners -o /tmp/nunit -version $NUNIT_VERSION && \
    ls /tmp/nunit && \
    mkdir /nunit && \
    cp /tmp/nunit/NUnit.ConsoleRunner.$NUNIT_VERSION/tools/* /nunit && \
    cp /tmp/nunit/NUnit.Extension.NUnitProjectLoader.$NUNIT_VERSION/tools/* /nunit && \
    cp /tmp/nunit/NUnit.Extension.NUnitV2Driver.$NUNIT_VERSION/tools/* /nunit && \
    cp /tmp/nunit/NUnit.Extension.NUnitV2ResultWriter.$NUNIT_VERSION/tools/* /nunit && \
    cp /tmp/nunit/NUnit.Extension.VSProjectLoader.$NUNIT_VERSION/tools/* /nunit && \
    apt-get clean

ENTRYPOINT ["mono", "/nunit/nunit3-console.exe"]

This means that I can use docker run craigvincent/nunit-console path/to/tests.dll to run the console, but in Gitlab I want to specify the image as the container the job should run in:

test:
  image: craigvincent/nunit-console
  stage: test
  tags: [bi, windows]
  script:
    - 'nunit-console ".\$env:TEST_FOLDER\Tests.dll"'  # running NUnit tests
  only:
    - main
  dependencies:
    - build

This does not work however:

$ & NUNIT3-CONSOLE ".\$env:TEST_FOLDER\Tests.dll"
& : The term 'NUNIT3-CONSOLE' is not recognized as the name of a cmdlet, function, script file, or operable program. Ch
eck the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\mfdev\AppData\Local\Temp\build_script344671059\script.ps1:237 char:3
+ & NUNIT3-CONSOLE ".\$env:TEST_FOLDER\Tests.dll"
+   ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (NUNIT3-CONSOLE:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit status 1
1 Answers

Create your own Dockerfile using mono:4.4 or craigvincent/nunit-console in the FROM step. Change the ENTRYPOINT to [].

FROM mono:4.4

ENV NUNIT_VERSION 3.4.1

...

ENTRYPOINT []

Add a build step to your pipeline to build and push this Dockerfile image to your GitLab registry. Then, use it as the test image.

Related