【问题标题】:How To Run GitHub Actions - .NET Framework Unit Test如何运行 GitHub Actions - .NET Framework 单元测试
【发布时间】:2022-07-26 08:39:45
【问题描述】:

我有一个带有简单 .NET Framework 4.8 库项目的示例解决方案。 这个解决方案也有这个库的单元测试项目。这个测试项目有一个会成功的测试和一个会失败的测试。 现在我想把它上传到 github,它应该运行测试项目。但我不知道如何运行测试项目。所有教程均适用于 .NET Core 5+

我的实际工作流文件如下所示:

name: .NET Framework Desktop

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:

  build:

    strategy:
      matrix:
        configuration: [Release]

    runs-on: self-hosted  # For a list of available runner types, refer to
                             # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on

    env:
      Solution_Name: SelfHostedPDMTest.sln                         # Replace with your solution name, i.e. MyWpfApp.sln.
      Test_Project_Path: TestProjectTest.csproj                 # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.
      Wap_Project_Directory: your-wap-project-directory-name    # Replace with the Wap project directory relative to the solution, i.e. MyWpfApp.Package.
      Wap_Project_Path: your-wap-project-path                   # Replace with the path to your Wap project, i.e. MyWpf.App.Package\MyWpfApp.Package.wapproj.

    steps:
    - name: Checkout
      uses: actions/checkout@v3
      with:
        fetch-depth: 0

    # Install the .NET Core workload
    - name: Install .NET
      uses: actions/setup-dotnet@v2
      with:
        dotnet-version: 5.0.x

    # Add  MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
    - name: Setup MSBuild.exe
      uses: microsoft/setup-msbuild@v1.0.2

    # Execute all unit tests in the solution
    - name: Execute unit tests
      run: dotnet test

    # Restore the application to populate the obj folder with RuntimeIdentifiers
    - name: Restore the application
      run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
      env:
        Configuration: ${{ matrix.configuration }}
        Appx_Bundle_Platforms: x86|x64
        Appx_Package_Build_Mode: StoreUpload

这是来自 github 的示例工作流。 我知道所选的 .net 版本是 5.0.x,但 4.8.x 是不可能的。 并且 dotnet test 将运行 .NET Core 测试而不是 .NET Framework 测试。 也许有人有一个很好的工作流程文件或者可以帮助我开始?

【问题讨论】:

    标签: github github-actions .net-4.8


    【解决方案1】:

    试试下面documented

    - name: Run vstests
      uses: microsoft/vstest-action@v1.0.0
      with:
        testAssembly: TestProject.dll
        searchFolder: .\TestProject\bin\Debug\
        runInParallel: true
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 2021-03-20
      • 1970-01-01
      • 1970-01-01
      • 2021-01-29
      • 1970-01-01
      相关资源
      最近更新 更多