Code Coverage with Visual Studio Test task - azure-devops

I have a project containing azure function implementations. My project .csproj file looks like below.
I haved added a test project for the same and implemented unit tests using Xunit. My test project .csproj looks like below.
I have added a Visual Studio Test task in my build definition with below configurations.
How can I include only project and test project for calculating code coverage?

You can use Run settings file which is the configuration file used by unit testing tools. Advanced code coverage settings are specified in a .runsettings file.
You can exclude specified assemblies from code coverage analysis. For example:
<ModulePaths>
<Exclude>
<ModulePath>Fabrikam.Math.UnitTest.dll</ModulePath>
<!-- Add more ModulePath nodes here. -->
</Exclude>
</ModulePaths>
Then add the .runsettings file in source control, specify the file under Setting file area in Visual Studio Test task
Please see Customize code coverage analysis for details.

Related

How to get a results file from Nunit Test Adapter ran in Visual Studio with Test Explorer

I have been running my tests with Specflow+ through Test Explorer in Visual Studio and a nice .html report is automatically generated at the end by the Specflow+ Runner.
I have switched to Nunit Test Runner (still running through Test Explorer).
However, at the end I can't see any results files at all xml or html?
How do I get it to generate these? Or am I looking in the wrong place?
I tried adding a .runsettings file in the root of the project containing the following code but still no results were written:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<NUnit>
<TestOutputXml>TestResults</TestOutputXml>
</NUnit>
</RunSettings>
It's necessary to tell TestExplorer to use the .runSettings file. See https://learn.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2019

Prevent a VS solution's project from being built by Appveyor

The .sln file in my GitHub repository has two projects -- a class library project, and a tests project. I only want AppVeyor to build the library project, because the tests project requires the Microsoft Access database engine to be installed.
I am using appveyor.yaml.
How can I do this?
You could switch from automatic msbuild mode to script mode, by adding a build_script section to your yaml config file. This might look something like this...
build_script:
- msbuild StringAsSql/StringAsSql.csproj /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
It's the same command AppVeyor would run automatically on your solution file.
There are a number of possible options here.
To disable tests, set the following in appveyor.yml:
tests: off
Or create a special build configuration (via the Visual Studio Configuration Manager...), say ReleaseCI, and specify the configuration in appveyor.yml:
configuration: ReleaseCI
Another option is to create multiple solution files; the UI for switching solutions is simpler (Solution Explorer -> Switch views...) than the UI for switching build configurations. To specify which .sln file should be passed to MSBuild:
build:
project: MySolution.sln

How to generate HTML report from jacoco.exec?

We have a Maven project which has submodules. There is one parent pom.xml
and each and every sub projects are made into a war file. Each and every submodule has unit test cases and reports generated from Jacoco.
The existing reports show unit test coverage of individual modules but we need to provide integration test-wide code coverage on Tomcat. What we did was we installed jacoco agent in Tomcat folder and configured it to to generate jacoco.exec. When I import jacoco.exec using EclEmma plugin we see the code coverage.
Is there any way to generate report from standalone jacoco.exec without source code?
Download Jacoco agent Zip file from the following URL:
https://www.jacoco.org/jacoco/ select the version that suits your needs.
Create folder with suitable name, I have mine located at "C:\jacoco". Extract the contents of the Zip file there.
Open CMD and go to C:\jacoco
Use the following command:
java -jar jacococli.jar report --classfiles path/of/the/class/files path/of/the/.exec file --html html/report/location --name nameOfTheReport
Note:
1. -jar : I have kept jacococli.jar in Jacoco.
2. --classfiles : Path of the compiled java files.
3. Path of the exec file.
4. --name : Name of HTML report Title (Heading)
Java code coverage report will be generated at your mentioned location.
Jacoco .exec files use a very optimised file format that contain compact bit sets of which checkpoints have been executed and which have not been executed, but contain no informations about line numbers.
So, to generate any report, .exec files need to be applied to class files, that contains line numbers as debug informations.
Class files are enough to produce xml reports, while also sources are needed to produce html reports (for the sake of generating html pages with coloured lines).
Most Jacoco tools to generate reports allow you to specify where to find classes and sources to properly generate reports, so if you can download those exec file to a develop machine where there are also classes and sources, you will be able to generate reports.

Call custom tool from TFS build

We are using TFS2010 for our web sites's builds and we're in the process of creating fully automated builds. At the moment the sites are built and deployed in remote servers.
The sites contains several configuration files that we would like to transform as part of the build. As there are some rules to create the correct config files we would like to use a custom tool for that purpose (.exe), not to use xml transformations for it.
From what we can see in the build template, MSBuild copies the files to a drop folder and then pushes them to the remote IIS site. We would like to hook our custom tool to this process and do the transformations in the build server before the site is published. The problem is that the MSBuild task is a single node in the build template and we can't find a place where to invoke our tool. Before the MSBuild step, there is no code deployed to the drop folder, after the MSBuild step the code was already deployed to the remote server.
Any ideas on how to plug the custom tool in the correct workflow step?
What is the msbuild target, that you use? I think you can define your own target in csproj file to do the following:
execute your custom tool against required files
run usual build target (or whatever target you normally use)
Edit
E.g. in a .csproj file you could define the following:
<Target Name="buildWithCustomTool">
<!-- Exec your custom tool -->
<Exec Command="your command" />
<!-- Call the build target which will run as normally -->
<CallTarget Targets="Build" />
</Target>
Hope it helps,
Ivan

App.config for SpecFlow not recognized by NUnit GUI runner

How do I get my App.config file to be recognized/used by the NUnit GUI runner? I have tried placing it in the top folder of my project and in the same folder as my feature files. Here are the contents of my App.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
</configSections>
<specFlow>
<runtime detectAmbiguousMatches="true"
stopAtFirstError="false"
missingOrPendingStepsOutcome="Error" />
</specFlow>
</configuration>
Specifically I am trying to tell NUnit to have a fail result when there is a missing or pending step which is why I am specifying "Error" for this. This actually works correctly when I use TestDriven.net but not when I use the NUnit GUI runner. The GUI always shows a green bar and displays the test as Inconclusive instead of Error or Failed.
I am launching the GUI with this command line argument:
E:\Program Files\NUnit 2.5.5\bin\net-2.0\nunit.exe "E:\ACSreader new work\ACSreader2 Working Copy\trunk\ACSreader2\ACSreader2.sln" /config:Test
Update concerning NUnit GUI Runner:
NUnit-Runner seems not to properly display/report inconclusive tests. An inconclusive test is displayed green in NUnit-GUI, while TestDriven and ReSharper display it yellow.
As shown in the question, SpecFlow can be configured to report missing steps as Errors and not as Inconclusive.
The configuration happens in the App.config of the project that contains the feature-files. The usual mechanism for App.config in .NET is applied. That means at runtime the config info has to be in a file called .dll.config. The runtime provides then the config to SpecFlow. SpecFlow does not read the config itself from App.config!
Make sure that at runtime the correctly named config file is present alongside the dll that contains the test fixtures. VisualStudio usually does that transparently when building a project.
Original answer:
The App.config has to be in the root folder of the project that is containing the test-fixtures (the project that contains the feature files).
Have a look at the examples on github. There are several App.config files in different projects:
http://github.com/techtalk/SpecFlow-Examples/tree/master/ASP.NET-MVC/BookShop/BookShop.AcceptanceTests/
http://github.com/techtalk/SpecFlow-Examples/tree/master/ASP.NET-MVC/BookShop/BookShop.AcceptanceTests.Selenium/
http://github.com/techtalk/SpecFlow-Examples/tree/master/BowlingKata/BowlingKata-MsTest/Bowling.SpecFlow/
See my answer nunit and configs
You need to tell nunit what the name of the config file is. it looks for namespace.config by default it seams