Aspiring agile software craftsman, clean code, polyglot, in love with different programming paradigm. I am on a never-ending journey towards mastery of software.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In this blog post, you will witness how multi-core CPU executes different processes and do context switching.
We will use the following program, this program merely takes input from the user and prints input string after some time periodically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I presume after compiling the above file, we get the output file: ‘OSPlayground.exe’.
Now open a command prompt and navigate to the path that contains the above binary. Run the following command and witness the magic.
Command to use: start /b OSPlayground && OSPlayground
Output:
The command prompt will ask you to enter the string a couple of times since we executed the program twice. I had inputted EARTH! for the first process from the command prompt and MARS! for another one.
The above program is executed on a multicore processor.
In this post, I will note down steps to collect human-readable code coverage for .net core/standard apps on the developer machine.
Big Picture of Code coverage collection.
I have created a simple .NET standard class library and .net core test project (xUnit) project here.
Project structure: .NET standard class library and xUnit test project
Prerequisites
You will require the following NuGet packages to be installed on the xUnit tests project (BeingCraftsman.CoverageDemo.Tests).
Microsoft.NET.Test.Sdk (Preinstalled as a part of xUnit tests project)
xunit (Preinstalled as a part of xUnit tests project)
xunit.runner.visualstudio (Preinstalled as a part of xUnit tests project)
coverlet.msbuild Install it using the command: dotnet add package coverlet.msbuild
ReportGenerator Install it using the following two commands: – dotnet new tool-manifest – dotnet tool install dotnet-reportgenerator-globaltool
Steps:
Open Powershell and navigate to the tests project directory (In my case, BeingCraftsman.CoverageDemo.Tests).
Check if the command dotnet test is running all tests.
Collect the coverage in a folder (./CodeCoverage in my case) and mention the format opencover. WHY opencover? ReportGenerator will generate a human-readable report but for that, it requires raw code coverage file in OpenCover format. dotnet test /p:CollectCoverage=true /p:CoverletOutput="./CodeCoverage/" /p:CoverletOutputFormat="opencover"
Convert opencover format to web pages (Human readable one). dotnet reportgenerator "-reports:.\CodeCoverage/coverage.opencover.xml" "-targetdir:.\CodeCoverage\Web"
Open generated report start .\CodeCoverage\Web\index.htm
Human readable code coverage report giving insights about class, methods etc…
Getting tired of running all these commands one by one. Next time, onwards, just combine them with “;” separated and execute.
The dotnet test command is used to execute unit tests in a given solution. The dotnet test command builds the solution and runs a test host application for each test project in the solution.
Coverlet is Cross platform code coverage for .NET. How it works.
Coverlet also integrates with the build system to run code coverage after tests. In our case, MSBuild is the build system and hence we are using this package. For other build systems, you would require another package.
ReportGenerator converts coverage reports generated by OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.