Search This Blog

Showing posts with label Unit Test. Show all posts
Showing posts with label Unit Test. Show all posts

Monday, 1 June 2020

Test Explorer (Visual Studio) shows 'Unknown Project'

Problem: Test Explorer (Visual Studio) shows '<Unknown project>'

 

Details: I created an class library project with Unit Tests project, and added a few unit tests. However, I have removed the failing test case from file but test explorer shows that Test Explore.


Solution

Steps as below

  1. Close Visual Sudio
  2. Go to project folder
  3. Find ".vs" folder. (Make sure your are also checking hidden item)
  4. Delete ".vs" folder.
  5. Good to go, Open visual studio, build and run project.



Wednesday, 30 October 2019

Cross-Platform Unit Testing and Code Coverage with Coverlet

How to check code coverage (using Unit Test cases)

Code coverage and report generation using coverlet (global tool).

Coverlet is a cross-platform code coverage framework for .NET, with support for the line, branch and method coverage. It works with .NET Framework on Windows and .NET Core on all supported platforms.


Steps as below
  • Step 1:Create the SetupGlobalTool.bat file in your project folder.
    Sample path: "C:\YourProjectFolder\BuildCodeCoverageReport\SetupGlobalTool.bat"
  • Step 2: Create the RunCodeCoverage.bat file in your project folder.
    Sample path: "C:\YourProjectFolder\BuildCodeCoverageReport\RunCodeCoverage.bat"
  • Step 3 Execute both file from command prompt respectively.
  • Note: File content provided in below seactions.

SetupGlobalTool.bat


@ECHO OFF

dotnet tool install --global coverlet.console  --ignore-failed-sources

dotnet tool install -g dotnet-reportgenerator-globaltool --ignore-failed-sources

pause

RunCodeCoverage.bat


@ECHO OFF

coverlet "..\TestProjectName\bin\Release\netcoreapp2.2\TestProjectName.dll" --target "dotnet" --targetargs "test ..\TestProjectName\TestProjectName.csproj -c Release --no-build --logger:trx" --threshold 0 --format "opencover" -f json -f lcov  --output "CodeCoverage"

reportgenerator "-reports:CodeCoverage.opencover.xml" "-targetdir:CodeCoverage\Reports"

pause

Note: Create the RunCodeCoverage.bat and SetupGlobalTool.bat file in BuildCodeCoverageReport folder.

Commands

  • Step 1: Install global tools.
    SetupGlobalTool.bat
  • To verify tools has been installed execute below command
    dotnet tool list -g
  • RunCodeCoverage.bat

Note: If command is not recognized, please check the environment variable PATH.

Sample Report

Creating a NuGet Package Feed to Host Artifacts

Step-by-Step Guide: Creating a NuGet Package Feed to Host Artifacts 🔹 Step 1: Create a C# Class Library and Generate NuG...

Recent Post