Starting NUnit runner (2.6.3) from Visual Studio - visual-studio-2010

I followed the instructions here to use "start external program" to start NUnit on my test project's dll. NUnit starts, but I get an error "This assembly was not built with any known testing framework"
I can run the same assembly with the same NUnit.exe from the command line just fine...
nunit.exe version 2.6.3
nunit.exe.config is as follows:
<configuration>
<!--
The GUI only runs under .NET 2.0 or higher. The
useLegacyV2RuntimeActivationPolicy setting only
applies under .NET 4.0 and permits use of mixed
mode assemblies, which would otherwise not load
correctly.
-->
<startup useLegacyV2RuntimeActivationPolicy="true">
<!-- Comment out the next line to force use of .NET 4.0 -->
</startup>
<runtime>
<!-- Ensure that test exceptions don't crash NUnit -->
<legacyUnhandledExceptionPolicy enabled="1"/>
<!-- Run partial trust V2 assemblies in full trust under .NET 4.0 -->
<loadFromRemoteSources enabled="true"/>
<!-- Look for addins in the addins directory for now -->
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib;addins"/>
</assemblyBinding>
</runtime>
</configuration>

OK, the answer is that I had to put the Command line argument in quotes.
e.g.
"C:\SVN\_branches\BUG-2261\Product\ProductTests\bin\Debug\ProductTests.dll"
I thought at first that this might be because there were spaces in the folder path for the dll but there aren't. It still need the quotes to make it work.

Related

DeploymentEnabled false is not working in my runsettings file

I currently updated to visual studio 2017 enterprise edition version 15.9.24 .
The issue that i'm running across is i'm not able to debug my test using the
runsettings file. When I debug the test its access any dlls and deployed files from my TestResults Out folder instead of bin/debug folder since i'm in debug mode. When i was running Visual studio 2015 I was using .testsettings file
and was able to run my test from the bin/debug folder. Since .testsettings is
going to be deprecated i decided to move to runsettings.
Searching the web and stack someone stated that i needed to have the settings located in the runsettings file that is labeled DeploymentEnabled to false to achieve this. I did this and still getting error because the application is running and trying to access the files from my TestResults Out folder. I also changed the run settings to forced legacy mode to true and added directory of my old test settings file but still not working.
Is there another setting that i'm not taken into consideration
or am i missing something or is something wrong with my run settings.
Please see my example of my current runsettings file below
Thanks for any help or direction given.
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Configurations that affect the Test Framework -->
<RunConfiguration>
<MaxCpuCount>1</MaxCpuCount>
<!-- Path relative to directory that contains .runsettings file
<ResultsDirectory>.\TestResults</ResultsDirectory> -->
<!-- x86 or x64 -->
<!-- You can also change it from the Test menu; choose "Processor Architecture for AnyCPU Projects" -->
<TargetPlatform>x86</TargetPlatform>
<!-- Framework35 | [Framework40] | Framework45 -->
<TargetFrameworkVersion>Framework45</TargetFrameworkVersion>
<!-- Path to Test Adapters -->
<!--<TestAdaptersPaths>%SystemDrive%\Temp\foo;%SystemDrive%\Temp\bar</TestAdaptersPaths>-->
<!-- TestSessionTimeout was introduced in Visual Studio 2017 version 15.5 -->
<!-- Specify timeout in milliseconds. A valid value should be greater than 0 -->
<TestSessionTimeout>15000000</TestSessionTimeout>
</RunConfiguration>
<!-- 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>
<ModulePaths>
<Exclude>
<ModulePath>.*CPPUnitTestFramework.*</ModulePath>
</Exclude>
</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>
<!-- Parameters used by tests at run time -->
<TestRunParameters>
<Parameter name="webAppUrl" value="http://localhost" />
<Parameter name="xxxxUser" value="xxxxm,xxxxtAuto01,xxxxtAuto02,xxxxxtAuto03,xxxxtAuto04" />
<Parameter name="xxxxxxxxxnbr" value="xx86,xx90,xx91,xx92,xx93" />
</TestRunParameters>
<!-- MSTest adapter -->
<MSTest>
<MapInconclusiveToFailed>true</MapInconclusiveToFailed>
<CaptureTraceOutput>false</CaptureTraceOutput>
<DeleteDeploymentDirectoryAfterTestRunIsComplete>true</DeleteDeploymentDirectoryAfterTestRunIsComplete>
<DeploymentEnabled>false</DeploymentEnabled>
<!---->
<ForcedLegacyMode>true</ForcedLegacyMode>
<SettingsFile>%xxxx_Automation_Test\xxxx_Automation_Test\xxx_Automation_Test\xxxxAutomation.testsettings;</SettingsFile>
<InProcMode>true</InProcMode>
<KeepExecutorAliveAfterLegacyRun>False</KeepExecutorAliveAfterLegacyRun>
<AssemblyResolution>
<!--
<Directory path="C:\xxx_Automation\xxxx_Automation_Test\xxx_Automation_Test\bin\" includeSubDirectories="false"/>-->
</AssemblyResolution>
</MSTest>
</RunSettings>
I updated my runsettings to have the file name of of run settings and to
update the ForcedLegacyMode to true.
<ForcedLegacyMode>true</ForcedLegacyMode>
<SettingsFile>xxxxxAutomation.testsettings</SettingsFile>
<KeepExecutorAliveAfterLegacyRun>False</KeepExecutorAliveAfterLegacyRun>
<AssemblyResolution>

Brackets are not included as Code Coverage for Unit Tests c# in VSO

There are some code coverage inconsistencies between the VSO build pipeline and Visual Studio local. We found that the code coverage in Visual Studio is higher because it counts brackets as part of the code coverage. But it doesnt count in VSO build pipeline for some reason. Anyone knows why? Is this a known bug in VSO?
We use Xunit and c# for the tests and have test.runsettings to exclude code. Below is the test.runsettings file
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Configurations that affect the Test Framework -->
<RunConfiguration>
<!-- Path relative to directory that contains .runsettings file-->
<ResultsDirectory>.\TestResults</ResultsDirectory>
<TargetPlatform>x64</TargetPlatform>
<MaxCpuCount>10000</MaxCpuCount>
</RunConfiguration>
<!-- 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>
<Attributes>
<Exclude>
<Attribute>^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
</Exclude>
</Attributes>
<ModulePaths>
<Exclude>
<ModulePath>.*unittests.dll$</ModulePath>
<ModulePath>.*integrationtests.dll$</ModulePath>
<ModulePath>.*xunit.*.dll</ModulePath>
<ModulePath>.*fluentassertions.*$</ModulePath>
<ModulePath>.*moq.*$</ModulePath>
<ModulePath>.*telemetry.extensions.ai.netcore.*$</ModulePath>
<ModulePath>.*newtonsoft.*$</ModulePath>
<ModulePath>.*codeanalysis.*$</ModulePath>
</Exclude>
</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>
</RunSettings>
The reason why it's showing inconsistent code coverage is because in Visual Studio, I was running Debug mode instead of Release mode. After changing it to Release mode, the number is consistent to the VSO number.

MS Test settings > TeamCity > 64bit

I've configured my .testsettings file as per instructions to run Hosts in 64bit.
But I don't see anything actually written to the settings file.
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="accounting" id="907240cb-5a90-45f4-a41f-2e73533c8c25" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
<Deployment enabled="false" />
<Execution>
<Timeouts runTimeout="1800000" testTimeout="40000" />
<TestTypeSpecific>
<UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
<AssemblyResolution>
<TestDirectory useLoadContext="true" />
</AssemblyResolution>
</UnitTestRunConfig>
</TestTypeSpecific>
<AgentRule name="LocalMachineDefaultRole">
</AgentRule>
</Execution>
<Properties />
</TestSettings>
And so my build server (Teamcity) continues to build in 32bit.
i've also tried setting it in VS but that definitely doesn't get persisted anywhere for Teamcity to know
how do i force Teamcity to use 64bit ?

VS 2015 cannot open .coveragexml generated by CodeCoverage.exe

I am following Code Coverage Results Import (C#, VB.NET) documentation for SonarQube.
For my project, I am able to generate test coverage binary file as "SonarQubeTests.csproj.coverage"
Visual Studio can open this file with no problem. I can see all the details.
Then when I try to generate ".coveragexml" file with following command;
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" "analyze /output:C:\SonarQubeTests.csproj.coveragexml C:\SonarQubeTests.csproj.coverage"
It does generate ".coveragexml" file, but when I try to open Visual Studio it gives me following error:
I can open this file with text editor and content seems all fine. But neither Visual Studio 2015 nor sonarqube does not read this file.
What I am missing here?
P.S I have also runner settings for Ms Test runner as below.
Not sure if this will effect something;
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Configurations that affect the Test Framework -->
<RunConfiguration>
<MaxCpuCount>1</MaxCpuCount>
<!-- Path relative to solution directory -->
<ResultsDirectory>C:\</ResultsDirectory>
<!-- [x86] | x64
- You can also change it from menu Test, Test Settings, Default Processor Architecture -->
<TargetPlatform>x86</TargetPlatform>
<!-- Framework35 | [Framework40] | Framework45 -->
<TargetFrameworkVersion>Framework45</TargetFrameworkVersion>
<!-- Path to Test Adapters -->
<TestAdaptersPaths>%SystemDrive%\Temp\foo;%SystemDrive%\Temp\bar</TestAdaptersPaths>
</RunConfiguration>
<!-- 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>
<ModulePaths>
<Exclude>
<ModulePath>.*CPPUnitTestFramework.*</ModulePath>
</Exclude>
</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>
<!-- Parameters used by tests at runtime -->
<TestRunParameters>
<Parameter name="webAppUrl" value="http://localhost" />
<Parameter name="webAppUserName" value="Admin" />
<Parameter name="webAppPassword" value="Password" />
</TestRunParameters>
<!-- Adapter Specific sections -->
<!-- MSTest adapter -->
<MSTest>
<MapInconclusiveToFailed>True</MapInconclusiveToFailed>
<CaptureTraceOutput>false</CaptureTraceOutput>
<DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete>
<DeploymentEnabled>False</DeploymentEnabled>
<AssemblyResolution>
<Directory Path="D:\myfolder\bin\" includeSubDirectories="false"/>
</AssemblyResolution>
</MSTest>
</RunSettings>
I think you could use vstest.console to get code coverage directly. We do not sure whether VS could open the code coverage that generated by third party tools.
I think if we could vstest.console to get the code coverage will has not problems. please try it to see the results.

How to add an assembly manifest to a .NET executable?

How can i add an assembly manifest to my .NET executable?
An assembly manifest is is an XML file that is added to a .NET portable executable (PE) with resource type RT_MANIFEST (24).
Assembly manifests are used to declare a number of things about the executable, e.g.:
If i want to disable DPI-scaling because i am a good developer:
<!-- We are high-dpi aware on Windows Vista -->
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
i can declare that i was designed and tested on Windows 7, and i should continue to depend on any bugs in Windows 7
<!-- We were designed and tested on Windows 7 -->
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates application support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
</application>
</compatibility>
i can declare that i am a good developer, and don't need file and registry virtualization
<!-- Disable file and registry virtualization -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
i can declare that i depend on a particular version 6 of the Microsoft Common Controls library:
<!-- Dependency on Common Controls version 6 -->
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"/>
</dependentAssembly>
</dependency>
i can declare that i depend on a particular version of GDI+:
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.GdiPlus" version="1.0.0.0" processorArchitecture="x86"
publicKeyToken="6595b64144ccf1df" language="*" />
</dependentAssembly>
</dependency>
In the olden days, we would create a resource script file (*.rc), e.g.:
wumpa.rc
1 24 AssemblyManifest.xml
add that file to the project, and the compiler would compile the .rc file; including resources in the final executable image.
Except Visual Studio 2010 doesn't seem to have a way to add a resource script file to a project.
How do i add a resource script to a project in Visual Studio 2010?
How do i add an assembly manifest to a project in Visual Studio 2010?
Note: Any solution must work in an environment with source control and multiple developers (e.g. hard-coded paths to probably not installed binaries will break the build and not work).
Bonus Chatter
VS2010/.NET: How to embed a resource in a .NET PE executable?
VS2005: How to embed a manifest in an assembly: let me count the ways... (can't be done)
Update: Michael Fox suggests that the project properties dialog can be used to include an assembly manifest, but he doesn't indicate where:
Update: Things I've tried:
From the project properties screen, select Application. Select radio option Icon and Manifest. Under Manifest leave the default option of Embed manifest with default settings:
Doesn't work because it embeds a manifest with default settings, rather than my settings.
Under Manifest, change the combo option to Create application without a manifest:
Doesn't work because it embeds no manifest
Under Resources select the Resource File radio option:
Doesn't work because you cannot select an assembly manifest (or a resource script that includes an assembly manifest)
Under Resources, select the Resource File radio option, then enter the path to an assembly manifest XML file:
Doesn't work because Visual Studio chokes when presented with an assembly manifest:
Under Resources, select the Resource File radio option, then enter the path to a resource script file:
Doesn't work because Visual Studio chokes when presented with a resource script:
Add the AssemblyManifest.xml to my project, then look for it in the Manifest combo box:
Doesn't work because the Assembly Manifest file isn't listed as an option
i have a dozen other things i can keep screenshotting (add a .rc file to the solution, look for it in the dropdown, select "no manifest" and change the wumpa.rc build action to various things, build the .rc file using a separate resource compiler, either manually, or a pre-build/msbuild step, and select that .res file as my resource). i'll stop adding extra bulk to my question and hope for an answer.
If you want to add custom information to your application's manifest, you can follow these steps:
Right-click on the project in the Solution Explorer.
Click "Add New Item".
Select "Application Manifest File".
This adds a file named app.manifest to your project, which you can open and modify as desired.
Similar steps, with screenshots, lifted from Declaring Managed Applications As DPI-Aware on MSDN:
In the Solution Explorer, right-click on your project, point to Add, and then click New Item.
In the Add New Item dialog box, select Application Manifest File, and then click Add. The app.manifest file appears.
Copy and paste the following text into the app.manifest file and then save.
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<!-- Disable file and registry virtualization. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<!-- <requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
-->
</requestedPrivileges>
</security>
</trustInfo>
<!-- We are high-dpi aware on Windows Vista -->
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
<!-- Declare that we were designed to work with Windows Vista and Windows 7-->
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates application support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates application support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
</application>
</compatibility>
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</asmv1:assembly>
In the Solution Explorer, right-click on the project, and then click Properties to verify that the app.manifest is used.
Your application is now manifested as required to be "designed for Windows", and is
disables file and registry virtualization
disables DWM scaling of applications
announces that you were designed and tested on Windows 7 and Windows Vista
takes a dependency on Common Controls library version 6 (enabling the use of visual styles by the common controls)
I have Visual Studio 2010 Professional with Service Pack 1 installed. I am running on Windows 7 Ultimate 64-bit. If I follow these instructions, the project properties shows "Embed manifest with default settings" in the resources block, and also the option is disabled! When I build, the manifest does not get embedded into the DLL as I verified by opening the DLL in resource view.
However, if I :
Locate the added app.manifest file in the Solution Explorer
Right-click and choose Properties
Change the Build Action property from "None" to "Embedded Resource"
Rebuild
The manifest file is embedded properly, which I can verify by loading the DLL into the resource view. The Manifest setting in the Application properties still shows as "Embed manifest with default settings" and is still disabled.
In Visual Studio 2008, this can be done in the Project Properties window. I'm almost positive it is the same in 2010. Right click on your project, select properties, and in the application tab you can select a manifest. You have to add it to your project first, but you can do that easily by adding an existing file.

Resources