Automated Code Coverage through command line/Azure Release pipeline (VSTest, MSTest) Getting coverage only for test dlls but not for .Net dlls) - code-coverage

I have a managed C++ Dll (ABC.dll) for which I have few unit tests in a separate dll (TestABC.dll).
If I run code coverage from Visual Studio I get coverage for both the dlls. So that is Ok.
Actually I have a release pipeline which installs application suit that contains TestABC.dll. I am trying to perform code coverage on this release pipeline. Here I am getting coverage only for TestABC.dll , but not for ABC.dll.
My question is do I need to instrument my DLL (ABC.dll). I am not using any runsettings file and my dll (ABC.dll) is delay signed.
Behavior is same If I am performing code coverage from command line.
"C:\Source\TestABC.dll" /EnableCodeCoverage /InIsolation /Logger:"trx" /TestAdapterPath:"C:\Source\output\x86\Debug\bin"
I have tried using .runsettings file but it didn't worked.
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0">
<Configuration>
<CodeCoverage>
<ModulePaths>
<Exclude>
<ModulePath>.*CPPUnitTestFramework.*</ModulePath>
</Exclude>
<Include>
<ModulePath>.*ABC.dll$</ModulePath>
</Include>
</ModulePaths>
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<CollectAspDotNet>False</CollectAspDotNet>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings> ```

Related

How do I specify a target architecture when building projects in Visual Studio code?

I am new to VS code/F# and I am trying to build a F# console app (on both Windows workstation and on my Linux computer).
I installed the Ionide extension together with FAKE.
The code I am considering is the Iris example (see How to translate the intro ML.Net demo to F#?), creating a New F# Project with Ionide and using Microsoft.ML.
My iris.fsproj is
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<DebugType>portable</DebugType>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Compile Include="iris.fs" />
<None Include="App.config" />
</ItemGroup>
<Import Project="..\.paket\Paket.Restore.targets" />
</Project>
When running the script (which I do with the "play" button aka F#: run script provided with VS Code/Ionide) I get:
C:\Users\MyUser\.nuget\packages\microsoft.ml\0.2.0\build\Microsoft.ML.targets(16,5): error : Microsoft.ML currently supports 'x64' processor architectures. Please ensure your application is targeting 'x64'.
together with
Running build failed.
Error:
System.Exception: dotnet build failed
How do I target x64 with the project structure provided by Ionide?
It should be as simple as adding the following line to your PropertyGroup section:
<PlatformTarget>x64</PlatformTarget>
There are more complicated setups possible using the Condition attribute to set the platform target based on various command-line arguments to the compiler, but that should be the simplest way to get you up and running.

junit plugin not showing results from all tests in jenkins

I have a test suite, where some of the XML files are generated after running unit tests (junit). And there are some other protractor automation tests which uses jasmine junit xml reporter (https://github.com/larrymyers/jasmine-reporters) to create XML file. I am generating both sets of XML files in same directory in my jenkins job, I have used junit plugin (Publish JUnit test result report) to publish report. So, now, after the job completes, 9 xmls are generated from unit tests and 2 XMLs are generated by jasmine-reporter, so as stated below from my jenkins job console output, it is able to recognize that there are 11 xml files from the pattern I have specified in job config.
22:49:52 [xUnit] [INFO] - [JUnit] - 11 test report file(s) were found with the
pattern '**/tests/target/failsafe-reports/junitreports/*.xml' relative to
'/home/jenkins/workspace/projectName' for the testing framework
'JUnit'.
But, problem is, when i click on "Test Result" link from jenkins job UI, it only shows all tests related to xml generated by unit test, and it doesn't show any result related to XML which was generated from jasmine report. Need help to know why jenkins is not showing any test result related to jasmine XML.
Below is a sample XML generated by unit test (which jenkins is showing in ui, when test result link is clicked).
<!--
Generated by org.testng.reporters.JUnitReportReporter
-->
<testsuite hostname="someHostName"
name="packageName.Class1" tests="22" failures="0" timestamp="16
Apr 2018 05:47:59 GMT" time="69.663" errors="0">
<testcase name="test1" time="2.488"
classname="packageName.Class1"/>
<testcase name="test2" time="5.808"
classname="packageName.Class1"/>
</testsuite>
Below is a sample XML generated by jasmine junit xml reporter (result of this is not shown by jenkins in it's UI, when clicking test result link)
<testsuites>
<testsuite name="chromeTestItemDetailsPage" timestamp="2018-04-16T05:48:43"
hostname="localhost" time="29.357" errors="0" tests="22" skipped="0"
disabled="0" failures="0">
<testcase classname="chromeTestItemDetailsPage" name="ItemTitleDisplayed"
time="0.895"/>
<testcase classname="chromeTestItemDetailsPage" name="ItemPriceDisplayed"
time="0.966"/>
</testsuite>
</testsuites>
I think you are encountering a Jenkins issue here.
Jenkins uses the attributes classname as well as testname of a <testcase> within a JUnit XML report to classify test results on the UI. Furthermore Jenkins expects the classname to be composed of a package name followed by a single dot and then a class name:
<testcase classname="packagename.classname" name="testname">
If no dot is present, Jenkins assumes the package "root". If multiple dots are present, only the last dot is recognized as separator. See this question for a better explanation.
If you look at your XML reports above you can notice, that the XML of the unit tests specify a package name in the classname attribute, while the XML of the jasmine reporter does not. I think the missing package name is the reason, why the test results are not showing up. Apparently Jenkins uses the package "root" only, if there are no packages present at all. If there is at least one test case with a package name, all other test cases without a package are "lost".
There are two possible solutions:
Report a bug for Jenkins since above behavior is unexpected
Modify the jasmine reporter to construct a classnameof the pattern package.class. There is a pull request at https://github.com/larrymyers/jasmine-reporters/pull/186/files that would allow modifications of the classname by a user function.

What format does the NUnit test results XML need to be to publish back to TFS 2010 build?

I have some xUnit tests running as part of a build and I need to post the results back to TFS 2010 so they show up in the build summary/log like normal tests would.
I execute the tests with the -nunit argument so that the output is an NUnit xml and not a xUnit one. I'm trying to use NUnit4TeamBuild to publish the results xml back to TFS and it looks like it's working but there's no test results anywhere at the end.
This is the detailed log for that step:
Publish xUnit Results
NUnitTfs.exe -n results.xml -t Project -b "Build_20171221.8" -v 2010
Loading NUnit Output from results.xml...
Transforming NUnit output to .trx file...
Adding build information to .trx file...
Publishing .trx file...
Checking test run does not exist...
Reading users identity...
Creating test run...
Creating test results...
Updating test run with details...
Uploading test run details...
Uploading assemblies...
Updating test results with details...
Uploading test result details...
The build finishes with 0 errors and 0 warnings but also says "No Test Results" in the build summary and there are no test results anywhere.
I have no idea why the tests aren't publishing.
Here's an example of the XML that it's trying to publish (note that I've changed the file paths and shortened the stack trace):
<?xml version="1.0" encoding="utf-8"?>
<test-results name="Test results" errors="0" inconclusive="0" ignored="0" invalid="0" not-run="0" date="2017-12-21" time="08:39:57" total="1" failures="1" skipped="0">
<environment os-version="unknown" platform="unknown" cwd="unknown" machine-name="unknown" user="unknown" user-domain="unknown" nunit-version="xUnit.net 2.3.1.3858" clr-version="64-bit .NET 4.0.30319.34209 [collection-per-class, non-parallel]" />
<culture-info current-culture="unknown" current-uiculture="unknown" />
<test-suite type="Assemblies" name="C:\Tests.DLL" executed="True" success="False" result="Failure" time="57.41">
<results>
<test-suite type="Assembly" executed="True" name="C:\Tests.DLL" result="Failure" success="False" time="57.410">
<results>
<test-suite type="TestCollection" executed="True" name="Tests" result="Failure" success="False" time="48.992">
<results>
<test-case name="Google_Search_Test" executed="True" result="Failure" success="False" time="48.9917024">
<failure>
<message>System.Exception : Test Failed. Exception has been thrown by the target of an invocation.</message>
<stack-trace>at Tests.Fixtures.Fixture.FormatException(Exception e) in... etc. </stack-trace>
</failure>
</test-case>
</results>
</test-suite>
</results>
</test-suite>
</results>
</test-suite>
</test-results>
TFS 2010 uses a proprietary results format with a “.trx” extension to publish results so we need to transpose the NUnit results before sending back through web services.
You can use NUnitTFS for xUnit, just try the workflow template NUnitAndPublishTemplate.xaml which provided by Ian Battersby.
Refer to Ian Battersby's blog for details : Running and publishing NUnit test results into TFS 2010

MSbuild error while chekout : exited with code 9009

I am try to chekout my file from TFS using MSBuild script. But I am getting "exited with code 9009"
My code is bellow :
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<TfCommand>
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe"
</TfCommand>
</PropertyGroup>
<Target Name="Build">
<Exec Command="$(TfCommand) checkout "$/ApplicationSharedServices/release/dev_branch/renderer/bin/MIME.dll""/>
</Target>
</Project>
As per Just TFS's answer, you need to be in the folder that is in your workspace before you run TF. it might work fine with VS but with MSBuild pure you need to be in the folder. Now you technically don't need to put the full path when doing the get then. just MIME.dll.
Just out of curiosity, why are you running an MSBuild TF get command? is this in you automated build? You should start using PowerShell and run a pre-build script to get the info you need. You could also use Nuget with package restore to get any DLLs needed for compilation.
Cheers,
ET

Emma instrumentation issue in <instr> ant task

I have an emma execution target in my ant script which captures the coverage for my project. Following is the ant script snippet from my emma target which worked fine until I added a new project which has the same package names(com.kuleep.project.*) as that of my existing project.
<emma enabled="${emma.enabled}" >
<instr instrpathref="test.run.classpath"
destdir="${kulproj.out.instr.dir}"
metadatafile="${kulproj.coverage.dir}/metadata.em"
merge="true">
<filter includes="com.kuleep.project.*" />
<filter excludes="com.kuldeep.project.test.*" />
</instr>
</emma>
After this new project was added the Emma Coverage Report shows the coverage for this new project's package and classes only. This means that the instrumented classes for my old project were overwritten by the instrumented classes of this new project since the package name is same in both projects.
What is the best way to avoid this and have instrumented classes for both projects generated if I do not want to change the package names in either of the projects.
NOTE: Please put a comment if more details are needed to answer this.

Resources