1

My unit tests reference files that are in the project and set to copy always. This passes.

[Test]
public void MyTest()
{
    // Arrange
    var json = File.ReadAllText("testfiles\\mytest.json");

    // Act & Assert
    Assert.IsNotNull(json);
}

In the CI/CD pipeline for GitHub, mytest.json is not found.

How do I get the mytest.json file deployed, or if it is deployed how do I get the test to fine it?

The YAML file - the default .NET one that gitHub generates for you

name: .NET

on:
  push:
    branches: [ "develop" ]
  pull_request:
    branches: [ "develop" ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Setup .NET
      uses: actions/setup-dotnet@v2
      with:
        dotnet-version: 6.x.x
    - name: Restore dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --no-restore
    - name: Test
      run: dotnet test --no-build --verbosity normal
riQQ
  • 9,878
  • 7
  • 49
  • 66
Omar.Ebrahim
  • 862
  • 1
  • 10
  • 30
  • please add a step `- run: ls testfiles/mytest.json` – rethab Jun 20 '22 at 09:09
  • I don't know dotnet, but might it make a difference whether you're using backslashes? Or does `ReadAllText` handle that to make sure it works on linux? – rethab Jun 20 '22 at 09:09
  • It was the platform it's running on. Setting it to `windows-latest` allowed them to pass. I would guess that on Linux, it's actually going to be looking in a different directory or the filename will be different. – Omar.Ebrahim Jun 20 '22 at 09:27
  • See https://stackoverflow.com/questions/38168391/cross-platform-file-name-handling-in-net-core if you want to handle files platform independently – riQQ Jun 20 '22 at 21:57

1 Answers1

1

Two things

Changing runs-on: ubuntu-latest to runs-on: windows-latest allowed the files to be output to the correct directory

Changing run: dotnet test --no-build --verbosity normal to run: dotnet test --verbosity normal helped as well.

Omar.Ebrahim
  • 862
  • 1
  • 10
  • 30