I have a .runsettings file which excludes autogenerated methods that are typically associated with async/await code, i.e. MoveNext() in my case. This is my .runsettings file:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<Functions>
<Exclude>
<Function>.*MoveNext.*</Function>
</Exclude>
</Functions>
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<CollectAspDotNet>False</CollectAspDotNet>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
This is the command I use to run my tests:
dotnet test --collect:"XPlat Code Coverage" --results-directory .coverage --settings tests.runsettings
If I enable logging I can see that it definitely finds the .runsettings file. However, all the generated coverage files include MoveNext() methods, e.g.
<class name="MyProject.Domain.Services.BackgroundService/<CreateMessages>d__10" filename="MyProject.Domain\Services\BackgroundService.cs" line-rate="0" branch-rate="0" complexity="2">
<methods>
<method name="MoveNext" signature="()" line-rate="0" branch-rate="0" complexity="2">
<lines>
<line number="71" hits="0" branch="False" />
<line number="72" hits="0" branch="False" />
<line number="73" hits="0" branch="True" condition-coverage="0% (0/2)">
<conditions>
<condition number="318" type="jump" coverage="0%" />
</conditions>
</line>
</lines>
</method>
</methods>
After the coverage reports are generated, I merge them using:
dotnet-coverage merge .coverage\*.xml --remove-input-files --recursive -f xml -o coverage.xml
The problem is that these methods are included in the coverage file, and our SonarQube scan job will occasionally fail with the error
[07:43:57]W: [Step 1/1] ERROR: Error during SonarQube Scanner execution
[07:43:57]W: [Step 1/1] ERROR: Line 132 is out of range in the file [...]
We traced this problem to one of those the auto-generated MoveNext() methods. Interestingly enough, when I merge the files using ReportGenerator it doesn't include these methods:
reportgenerator -reports:.coverage/**/*.cobertura.xml -reporttypes:Cobertura -targetdir:.
I can then "merge" the files to get into the correct format using:
dotnet-coverage merge .\Cobertura.xml -f xml -o coverage.xml
This gives me a coverage file with the MoveNext() methods excluded, and SonarQube is happy. This is a needless complexity though, and I would prefer just to have them excluded by Coverlet.
Is there any way to achieve this?
Related
I am trying to get CodeCoverage of my Unit Test for .Net assemblies. Though I am getting .Coverage files but It does not have any content in it. (Empty).
I am using following command through command line:
'"vstest.console.exe" "C:\MyCode\bin\TestABC.dll" "C:\MyCode\bin\TestClassAdi.dll" /TestCaseFilter:"FullyQualifiedName~TestABC.Func1" /EnableCodeCoverage /Logger:"trx" '
I have tried to run above command using runsettings file as well.
'''
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Configurations for data collectors -->
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<SymbolSearchPaths>
<Path>C:\MyCode\bin\</Path>
</SymbolSearchPaths>
<ModulePaths>
<Exclude>
<ModulePath>.*CPPUnitTestFramework.*</ModulePath>
</Exclude>
<Include>
<ModulePath>C:\MyCode\bin\</ModulePath>
<ModulePath>.*\.exe$</ModulePath>
</Include>
</ModulePaths>
<!-- We recommend you do not change the following values: -->
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<CollectAspDotNet>False</CollectAspDotNet>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
<MSTest>
<MapInconclusiveToFailed>True</MapInconclusiveToFailed>
<CaptureTraceOutput>false</CaptureTraceOutput>
<DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete>
<DeploymentEnabled>False</DeploymentEnabled>
<AssemblyResolution>
<Directory path="C:\MyCode\bin\" includeSubDirectories="false"/>
</AssemblyResolution>
</MSTest>
</RunSettings>
'''
I have Nlog configuration in the web config file and I would like to change the file path in the CD pipeline in order to put some dynamic path based on the environment.
Right now the web.config file variable substitution (XML Variable Substitution option) does not support it.
What are the other ways this can be done? I really don't have a choice to go the Web.Config transformation approach.
Any guidance on this will really help.
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwExceptions="false"
internalLogLevel="Error" internalLogFile="c:\Logs\nlog-internal.log">
<targets name="nlogconfig" async="true">
<target xsi:type="File" name="name"
fileName="Path/${shortdate}.log"
archiveFileName="Path/${shortdate}.{###}.log"
layout="${longdate} ${uppercase:${level}} ${callsite:className=true:includeSourcePath=true:methodName=true:skipFrames=1:cleanNamesOfAnonymousDelegates=true} ${newline} ${message} ${newline} ${exception:innerFormat=ToString:maxInnerExceptionLevel=2:innerExceptionSeparator=newline:separator=newline:format=ToString,StackTrace}${newline}"
archiveAboveSize="8388608"
archiveNumbering="Rolling"
archiveEvery="Day"
concurrentWrites="true"
maxArchiveFiles="100" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="name" />
</rules>
</nlog>
What are the other ways this can be done?
You could use the Replace Token task from Replace Tokens Extension.
Here are my steps, you could refer to them:
Nlog configuration:
<targets>
<target name="logfile" xsi:type="File" fileName="#{variable}#/#{shortdate}#.log />
<target name="logconsole" xsi:type="Console" />
</targets>
Replace Token task sample:
- task: replacetokens#3
inputs:
rootDirectory: 'Folder Path'
targetFiles: '**/*.config'
encoding: 'auto'
writeBOM: true
actionOnMissing: 'warn'
keepToken: false
tokenPrefix: '#{'
tokenSuffix: '}#'
useLegacyPattern: false
enableTelemetry: true
Variable:
Then the variables in Nlog configuration will be replaced.
Alternative solution is to deploy an environment-specific override-file next to the default NLog.config.
Example of environment-specific NLog.override.config:
<nlog>
<variable name="LogDirectory" value="D:/Path" />
</nlog>
Example of NLog.config:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="LogDirectory" value="${basedir}" /> <!-- Default Value -->
<include file="NLog.override.config" ignoreErrors="true" /> <!-- Override Value -->
<targets async="true">
<target xsi:type="File" name="name" fileName="${LogDirectory}/${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="name" />
</rules>
</nlog>
The deployment-package could include multiple nlog.override.config-files. One for each environment and just deploy the right one based on chosen environment.
See also: https://github.com/nlog/nlog/wiki/Configuration-file#include-files
I've read all the tutorials and examples, and still cannot publish a set of custom jars in my local Ivy repository.
Edit: Basically I want the same behavior as maven-install-plugin.
Here's my setup. I have an Ant task which produces the jars in a given folder. The folder name is not fixed but rather passed as a property in file. I want to get all the jars in this folder and install them in my local Ivy repo so that I can use them on a next step.
Here is my Ant from where I call the ivy:publish:
<project name="Install Ivy Dependencies" xmlns:ivy="antlib:org.apache.ivy.ant" basedir="." default="publish">
<loadproperties srcFile="path_to_folder.properties"/>
<property name="file_pattern" value="${path_to_folder}/[artifact].[ext]" />
<property name="pub_revision" value="1.0.0" />
<target name="resolve">
<ivy:configure file="ivysettings.xml" />
<ivy:resolve file="ivy.xml" />
</target>
<target name="retrieve-all" depends="resolve">
<ivy:retrieve pattern="${file_pattern}" conf="*" />
</target>
<target name="publish" depends="retrieve-all">
<ivy:publish resolver="local" organisation="myOrg" update="true" overwrite="true" pubrevision="${pub_revision}">
<artifacts pattern="${file_pattern}"/>
</ivy:publish>
</target>
</project>
Here's my ivysettings.xml:
<ivysettings>
<resolvers>
<filesystem name="local" local="true"/>
</resolvers>
</ivysettings>
And the ivy.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="myOrg" module="myModule" revision="1.0.0"/>
<publications>
<artifact name="my-custom-jar" ext="jar" type="jar"/>
<artifact name="my-custom-jar-source" ext="jar" type="source"/>
</publications>
</ivy-module>
The error that I am getting when I call the ant task is:
impossible to publish artifacts for myOrg#myModule;1.0.0: java.lang.IllegalStateException: impossible to publish myOrg#myModule;1.0.0!my-custom-jar.jar using local: no artifact pattern defined
I've managed to run my scenario and to resolve my issues using this tutorial There were two major issues in my code/integration.
First one is that you cannot tell Ivy to publish the artifacts in its repository without providing a path to it. I did this with the filesystem resolver:
<filesystem name="local" local="true" transactional="local">
<ivy pattern="${ivy.default.ivy.user.dir}/local/[module]/ivy-[revision].xml" />
<artifact pattern="${ivy.default.ivy.user.dir}/local/[module]/[artifact]-[revision].[ext]" />
</filesystem>
The stupid think about it is this should be build in. If you copy it as is, then everything works. If the config is different, or pointing to a different location - nothing works and you are not told why. I read tons of docs about Apache Ivy and it was nowhere mentioned that these patterns should point to the local Ivy repository. I thought these were the paths from where the jars should be taken. I actually complained about this, but the Ivy documentation is very confusing. Also I think the examples there are wrong. Who would like to publish the artifacts in their ivy.settings.dir. In my case this directory was in my repository!
There was a second issue. It is a smaller one and again very hard to see and fix. There's something wrong the revision param and again the documentation is messed up. If you specify one and the same string for the revision and pub revision the artifacts aren't publish without any explanation why. I fixed it by removing the revision from ivy.xml file.
Last, but not least, I didn't manage to run successfully the "thing" as Ant task, but with java -jar $IVY_JAR ... Maybe the issue was because of the versions, but I was too tired to try it with the fix.
P.S.#cantSleepNow thanks for the help.
You need to add artifact pattern to resolver in ivysettings.xml, something like (example from ivy documentation):
<ivysettings>
<resolvers>
<filesystem name="local" local="true">
<ivy pattern="${ivy.settings.dir}/1/[organisation]/[module]/ivys/ivy-[revision].xml"/>
<artifact pattern="${ivy.settings.dir}/1/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"/>
</filesystem>
</resolvers>
</ivysettings>
config.xml (build file)
Ant script to create An Oracle Service Bus Config Jar from file system.
<target name="run">
<taskdef name="configjar" classname="com.bea.alsb.tools.configjar.ant.ConfigJarTask"/>
<property name="task.failonerror" value="true" />
<property name="task.errorproperty" value="" />
<property name="settingsFile" value="C:\Oracle\Middleware\Oracle_Home\osb\tools\configjar\config.xml"/>
<property name="WL_HOME" value="C:\Oracle\Middleware\Oracle_Home\wlserver" />
<property name="MW_HOME" value="C:\Oracle\Middleware\Oracle_Home\" />
<property name="OSB_HOME" value="C:\Oracle\Middleware\Oracle_Home\osb" />
<!--configjar failonerror="${task.failonerror}" errorProperty="${task.errorproperty}" settingsFile="${settingsFile}" -->
<configjar settingsFile="${settingsFile}" >
</configjar>
</target>
my settings file :
<?xml version="1.0" encoding="utf-8"?>
<configjarSettings xmlns="http://www.bea.com/alsb/tools/configjar/config">
<source>
<project dir="D:\JDeveloper\mywork\ServiceBusApplication2" />
<!--extensionMapping>
<mapping type="str1234" extensions="str1234" />
</extensionMapping-->
<!--fileset>
<include name="str1234" />
<exclude name="str1234" />
</fileset-->
</source>
<configjar jar="SBProject.jar" overwrite="false">
<projectLevel includeSystem="true">
<project>SBProject</project>
</projectLevel>
</configjar>
</configjarSettings>
I have set weblogic environment variable on command prompt , globally using environment variable section of Windows but still not luck.
I am stuck at this point.Need solution on the same.
I am using soa12c.And this is osb script for creation of configuration jar file for osb application.
Go to D:\Oracles\Middleware12c\osb\tools\configjar and run setenv.cmd. On the same cmd try running your ant script. It might ask for MW_HOME, set that also.
Problem description:
The setup is executing Ant build script with TestNG target, which then loads testng.xml file. There is a possibility to specify listeners in both Ant file and testng.xml.
The questions arising are following:
Will both set up ways be supported? Will all the listeners specified in both configuration location be used during test execution?
Will any of listeners be prioritized over another? If yes, how?
Sample set up:
Ant file:
<project>
<property name="classes.dir" path="<my_classes_dir>" />
<property name="test.dir" path="<my_test_dir>" />
<target name="run-test">
<testng useDefaultListeners="false"
listeners="org.testng.reporters.EmailableReporter, org.testng.reporters.XMLReporter, com.example.MyCustomReporter">
<classpath>
<path path="${classes.dir}" />
</classpath>
<xmlfileset dir="${test.dir}" includes="testng.xml" />
</testng>
</target>
</project>
TestNG.xml:
<suite name="MyTestSuite">
<listeners>
<listener class-name="com.example.MyListener" />
<listener class-name="org.testng.reporters.FailedReporter" />
</listeners>
<test name="MyTest1">
<classes>
<class name="com.example.MyTest1" />
</classes>
</test>
</suite>
Background:
I have to support existing project which uses set up similar to the one described above. The Ant build file disables default reporters. Without touching Ant build file, I would like to specify additional report listeners (FailedReporter and/or any custom ones) for my tests in testng.xml.
I believe all listeners should be run, in your build file as well as in your testng.xml.
The testng.xml listeners would be executed second.
If the same listener is listed in both, build file and testng.xml, it would be executed twice.
This is based on my experience with Maven, but I guess, with ant it should be the same.
Also the order of listeners specified in testng.xml cannot be guaranteed in case both are implementing the same set of interfaces.
Hope it helps.