Haha
Haha

Reputation: 167

docker compose redis with .net core integration test

I'm trying to run integration test with redis in docker. I have .yml file setup as follows but when I run docker compose up it doesnt show the test results or doesnt run the dockerfile at all, but it responds with success and shows the redis and test container are created. The redis container stays up but the test exits quickly. What do I have to change to view the test results or even to check if its running the tests?

version: '3.4'

services:  
  redis-service:
    image: redis
    container_name: redis
    restart: on-failure
    ports:
      - "6379:6379" 
  test-service:
    image:  ${DOCKER_REGISTRY-}redistest
    depends_on:
      - redis-service
    build:
      context: .
      dockerfile: tests/RedisTest/Dockerfile

And here is the docker file

FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["tests/RedisTest/RedisTest.csproj", "tests/RedisTest/"]
RUN dotnet restore "tests/RedisTest/RedisTest.csproj"
COPY . .
RUN dotnet test "/src/tests/RedisTest/RedisTest.csproj" -c Release --logger "trx;LogFileName=test_results.trx"

Upvotes: 0

Views: 865

Answers (1)

Haha
Haha

Reputation: 167

I finally found the problem

  1. Remove image: ${DOCKER_REGISTRY-}redistest from the test-service since we are not building from an image rather from the docker file
  2. The most important one: I was stupidly using RUN and CMD interchangeably. Replacing RUN command with CMD will run the test after both containers are started.

Upvotes: 1

Related Questions