Visual Studio 2015 ordered test. How to use .runsettings - unit-testing

I am having difficulty building an ordered test in Visual Studio 2015 Enterprise (Update 1) and having the unit tests within the ordered test be able to reference my .runsettings.
Specifically, I need to access the TestRunParameters defined in the .runsettings file.
In any of my test methods, if I access the Properties of the TestContext, the properties I defined in the .runsettings are not found.
Surely I'm not the first to do this. Any help would be appreciated.

I think I understand the bug in Visual Studio. Whenever you select a runsettings file in the VS->Test->Test Settings submenu, they do NOT take effect until I at least do a Rebuild of my Test project (or a Clean solution / Build solution). Simply building does NOT make VS apply the proper runsettings file. There were certain situations where it wasn't applying any runsettings file, but since I started doing a Rebuild Project every time I select a different runsettings file, I've never discovered the TestContext not having my Proerties.

Related

How to exclude files in VSTS build but keep them under repository

I have a dot-net project build with VISUAL STUDIO 2015 4.6.1 framework and I have two independent program folders in the source code which has some build errors. There are no references to these programs from the main program.
When I push the whole source code onto VSTS I get build errors. So now I need a way to exclude those two folders from the manual build for now but may need them later after they are debugged so I don't want to delete them from VSTS too.
Can someone suggest?
Use an MS Build project file. Create an MSBuild project file from scratch
And the at the build solution step in VSTS, select or type the project file path instead of the solution file.
You will have to remove it down the road though. The maintenance tasks tend to be hard and counter-intuitive whenever the code base grows quickly. Visual Studio will not warn you if you have build errors (like obsolete path) in the MS Build project file.

VS2012 Unit Tests: How to change the location of the TestResults folder

I have all my Unit Test project in a folder under my Solution Folder and would like to have the TestResults folder in the same folder as the Test projects instead in the solution directory.
I have found that this could be done via the test seeting file:
How to specify the location for the unit test results in VS 2010?
but I also read, that with VS2012 you should no longer use tests settings files. Actually VS2012 does not create one.
Is there another way?
To specify a different location for the "TestSettings" folder, add a .runsettings to your solution as explained in the Visual Studio documentation: http://msdn.microsoft.com/en-us/library/vstudio/jj635153.aspx
My .runsettings file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<ResultsDirectory>.\Visual Studio Test Results</ResultsDirectory>
</RunConfiguration>
</RunSettings>
As far as I could tell, however, the ResultsDirectory location is not relative to the solution folder (like the example file from the doc suggests), but rather relative to the location of the .runsettings file itself. Also note that Visual Studio macros like $(SolutionDir) are not expanded here.
All in all, .runsettings files are not related to a particular project or solution.
The reason why they recommend using .runsettings files instead of .testsettings in newer version of Visual Studio is also found in the documentation: http://msdn.microsoft.com/en-us/library/vstudio/ee256991.aspx
If you use a .testsettings file, the MSTest test framework will be
used to run your tests. This runs more slowly and does not allow you
to run tests from third-party test frameworks.
You can create a small RunSettings file which looks like
<RunSettings>
<RunConfiguration>
<ResultsDirectory>e:\myResultsFolder</ResultsDirectory>
</RunConfiguration>
</RunSettings>
Select this setting file via top level menu Test->TestSettings->"Select Test Settings" before running your tests.
You can find more detail on http://msdn.microsoft.com/en-us/library/jj635153.aspx.

Debugging native/managed C++ in VS 2010 with NUnit

Is there a way to set breakpoints and step through them using NUnit with a mixed project of native C++ and managed C++?
I have my SUT (Software Under Test) configured as a static library (native C++)
I have my unit test suite as a separate project configured as a dll that depends on my previously stated library. I also added said library as a reference to my unit test project.
My tests run fine in NUnit, breakpoints just don't work.
Again, is there a way to get the breakpoints to work with NUnit with Native/Managed C++?
The most convenient way to do this is to set up a custom tool entry specifying the path to NUnit as the command. For a VS2003 C# project, you can use $(TargetPath) for the arguments and $(TargetDir) for the initial directory.
With Visual Studio VS2005 this becomes a bit harder, because that release changed the meaning of the 'Target' macros so they now point to the intermediate 'obj' directories rather than the final output in one of the 'bin' directories. Here are some alternatives that work in both versions:
$(ProjectDir)$(ProjectFileName) to open the VS Project rather than the assembly. If you use this approach, be sure to rename your config file accordingly and put it in the same directory as the VS project file.
$(ProjectDir)bin/Debug/$(TargetName)$(TargetExt) to run the assembly directly. Note that this requires hard-coding part of the path, including the configuration.
If you would like to debug your tests, use the Visual Studio Debug | Processes… menu item to attach to NUnit after starting it and set breakpoints in your test code as desired before running the tests.

MSBuild/TFS Build property for the test results out directory path

I am running a build using TFS 2008 to build a Visual Studio 2010 solution. The build is set to run unit tests, and when it does, it creates a folder such as this to hold the test results:
D:\Temp\MyApp\MyApp.Dev\TestResults\MyAccount_MyBuildServerName 2010-07-29 18_07_00_Any CPU_Release\Out\
Is there a built-in property I can use in the TFSBuild.proj file to get the path above? I would like to reference something like "$(TestResultsOutFolderPath)" in my build file, but I don't know if such a property exists. So far the only properties I have found only get me to the "TestResults" level and do not add the dynamic folder that contains the timestamp info which I need. Thank you.
I guess there is no built-in property for that. But, you can create your own property in TFSBuild.proj under the PropertyGroup element like
<PropertyGroup>
<TestResultsOutFolderPath>...</TestResultsOutFolderPath>
</PropertyGroup>
you can create the full path by combining the built-in TFS properties
some are listed at TFS Properties

Visual Studio: Run C++ project Post-Build Event even if project is up-to-date

In Visual Studio (2008) is it possible to force the Post-Build Event for a C++ project to run even if the project is up-to-date?
Specifically, I have a project which builds a COM in-process server DLL. The project has a post-build step which runs "regsvr32.exe $(TargetPath)". This runs fine on a "Rebuild", but runs on a "Build" only if changes have been made to the project's source.
If I do a "Build" without making any changes, Visual Studio simply reports that the project is up-to-date and does nothing - the Post-Build Event is not run. Is there any way that I can force the Event to run in this situation? This is necessary since although the DLL itself is up-to-date, the registration information may not be.
You can use the Custom Build Step property page to set up a batch file to run. This runs if the File specified in the Outputs setting is not found, or is out-of-date. Simply specify some non-existent file there, and the custom build step will always run. It will run even if your project is up-to-date, since the Output file is never found.
Use this DisableFastUpToDateCheck
See an example:
<PropertyGroup>
<PostBuildEvent>IF EXIST C:\Projects\Copy_Files_To_Instance.ps1 ( powershell -file C:\Projects\Copy_Files_To_Instance.ps1)</PostBuildEvent>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
The registration information is determined largely by what's in the .rgs file. If that file changes the project will get built. I am not sure how else COM registration can change without making the project dirty. Do you mind providing more details about your particular situation?
In Visual Studio 2017 (perhaps other versions as well), for C# projects (haven't checked for C++ projects per OP's actual question) there is an option for "Run the post-build event:", and one option is "Always", which will run the Post-Build even if nothing has changed, rather than simply reporting that the project is up to date: