In the reports folder to see the generated report. Report Generator will create the reports in d:\temp\reports folder. ReportGenerator "-reports:d:\temp\codecoverage.xml" "-targetdir:d:\temp\reports" Path=%path% C:\Users\Siddharth\.nuget\packages\reportgenerator\4.8.12\tools\net5.0\ Let's add the report generator's folder to the PATH variable and run the tool: The package gets installed at C:\Users\ \.nuget\packages\reportgenerator\4.8.12 Install-Package ReportGenerator -Version 4.8.12 Run the nuget command as shown in the website from within Visual Studio: Since this comes in the form of a nuget package, The first thing to do is install Report Generator. Now, to make this file readable for us humans we'll use the Report Generator. "-targetargs:D:\Temp\Sample-UnitTest\Sample\SampleLibTests\bin\Debug\netcoreapp3.1\SampleLibTests.dll" "-target:nunit3-console.exe" "-output:d:\temp\codecoverage.xml" -filter:"+* -*" We can pass a filter to OpenCover to remove these unwanted entries: If you notice, it also contains information about modules we aren't necessarily interested in e.g.: This files contains a lot of information but isn't very readable. OpenCover generates a file named "results.xml" which contains the code coverage information. You should now have a folder named "CodeCoverage" in the same folder where you executed the aboveĬommand. "-targetargs:D:\Temp\Sample-UnitTest\Sample\SampleLibTests\bin\Debug\netcoreapp3.1\SampleLibTests.dll" "-target:nunit3-console.exe" "-output:d:\temp\codecoverage.xml" Running the following command will generate the code coverage metric: Path=%path% C:\Utilities\NUnit.Console-3.12.0\bin\netcoreapp3.1 To make it easy to locate the binaries of OpenCover and NUnit, its a good idea to add these folders I have extracted OpenCover to c:\Utilities. Builds can be downloadedĪll you need to do is download and extract the zip file. OpenCover is the tool which measures the code coverage of your unit test cases. This is just to check if NUnit console runner is setup properly. If everything goes fine, the result of the tests will be stored in a file called TestResult.xml. Note, you must have already built theĬ:\Utilities\NUnit.Console-3.12.0\bin\netcoreapp3.1>nunit3-console D:\Temp\Sample-UnitTest\Sample\SampleLibTests\bin\Debug\netcoreapp3.1\SampleLibTests.dll Runs all the unit tests found in the specified assembly. Note, I have unzipped NUnit to c:\Utilities. NET core library, we need to use the console runner present in Nunit console runner (NUnit.Console-3.12.0.msi).ĭownload the NUnit.Console-3.12.0.zip file. We need the following software to do this: What we want to do now is generate code coverage reports for our unit tests. It contains 3 test methods to test the correctness of the Fibonacci generator. SampleLibTests is a NUnit Test type project which targets. The main library is accompanied by a separate library creates solely for housing theĪutomated unit tests. Single class for generating the Fibonacci sequence. NET Standard 2.1 as the target framework. SampleLib is aĬlass library which is set to use. The sample application is a library which generates the Fibonacci sequence. CodeĬoverage is measured on the basis of multiple criteria like:ĭetails of code coverage is covered quite well in Wikipedia. Its a measure of the amout of code which has been tested via automated unit testing. Writing unit tests, right? Right? This blog post discusses how to generate unit test codeĬoverage using NUnit, Open Cover and Report Generator. None of us put code into production without Automated unit testing needs to introduction.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |