Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Run GitHub Actions - .NET Framework Unit Test

I have a Sample Solution with a simple .NET Framework 4.8 Library Project. this Solution has also a Unit Test Project for this Library. This Test Project has a Test which will succeed and one Test which will fail. Now i want to upload this to github and it should Run the Test Project. But i cant figure out, how i can run the Test Project. All Tutorials are for .NET Core 5+

my actual workflow file looks like this:

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/[email protected]

    # 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

This is a sample Workflow from github. i know the selected .net version is 5.0.x but 4.8.x is not possible. and also dotnet test would run a .NET Core Test and not a .NET Framework Test. Maybe someone has a good workflow file or can help me to start?

like image 653
Martin Bartolomé Avatar asked Oct 20 '25 01:10

Martin Bartolomé


1 Answers

Try the below as documented

- name: Run vstests
  uses: microsoft/[email protected]
  with:
    testAssembly: TestProject.dll
    searchFolder: .\TestProject\bin\Debug\
    runInParallel: true
like image 106
Joy George Kunjikkuru Avatar answered Oct 22 '25 04:10

Joy George Kunjikkuru