用于CI/CD管道中未找到的单元测试的文件

发布于 2025-02-08 19:42:41 字数 903 浏览 0 评论 0原文

我的单元测试项目中的参考文件并设置为始终复制。这过去了。

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

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

在GitHub的CI/CD管道中,找不到mytest.json

如何获得部署的mytest.json文件,或者如果部署了文件,如何将测试罚款?

yaml文件 - github为您生成的默认.NET

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瀞厅☆埖开 2025-02-15 19:42:41

两件事

更改运行:ubuntu-latest to runs-on:windows-latest允许将文件输出到正确的目录

更改run:dotnet test -no-Build - Verbosity normal to 运行:dotnet test-verbosity normal也有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文