I have a local nuget package which contains a single test. The test is decorated with [TestClass] and it's test method is [TestMethod].
The reason this is a nuget package is because this test will be brought in to any test projects in order to test that a t4 transform has occurred in the referenced assemblies. The t4 template generates classes dynamically and I want the test to run to verify the t4 template has been executed (using reflection to make sure the generated classes have the expected methods)
When I reference the nuget package, the Visual Studio Test Explorer never displays the test. I was under the impression that VS reflected over the types in the assemblies to build it's test list, but that seems to be an incorrect assumption.
Is there a configuration setting or something that I am missing in order to have the test discovered?
Thank you,
Jason
Visual Studio Test Explorer can only run tests from multiple test projects in a solution and from test classes that are part of the production code projects.
There are two workarounds for your scenario:
Run the test from command line.
Instead of placing the generated dll file in the nuget package, placing the test class file in the "content" folder of the nuget package. This will add the test class file to your project when install the nuget package and then Test Explorer will detect the tests after building the solution.
Related
I have a local .Net Standard 2.0 library project and separate Xunit test project as part of a VS2017 solution. Library and Xunit tests successfully build with VS2017 and tests all succeed.
I uploaded the Git repository to VSTS. I am attempting to Build the two projects and then run the tests. The Restore step succeeds. However, the Build step successfully compiles the library, but the tests fail because the reference to the library dll is not found.
I have searched the Internet and have not found anything that helps me solve this. I assume that there is something simple to do that fixes this but ....
I am trying to run Nunit Test using Visual Studio test Runner from XAML build in TFS,but i am getting error saying
TF900547: The directory containing the assemblies for the Visual Studio Test Runner is not valid ''.
Based on your history, I assume you are using VSTS, you can refer to these steps to run Nunit test:
Create a unit test project via VS
Install NUnit and NUnit3TestAdapter packages
Add solution to source control (if the package files not added to the source control, you can refer to the steps below)
Open Source Control Explorer in VS
Add a new folder (e.g. Tools) and add Nuget.exe to the source control
Add bat file to your test project (For example: Tools\nuget35.exe restore NUTest2\NUTest2.sln)
Open XAML build definition and map Tools source folder to agent
Select Process section
Choose TfvcTemplate.12.xaml build template
In the Advance section of Build, specify Pre-build script path with previous bat file.
I have a unit two unit test files in Visual Studio 2012. When I build the project and go to the Test Explorer, I only have the unit tests from the first test file. Both test files classes have the same namespaces included and the classes are decorated with the [TestClass] attribute, the methods with [TestMethod] attribute.
What do I need to do to include the second text class?
Did you make it public?
Did you clean and build the solution?
Try Exit and re enter the VS2012.
It happend to me too and the above actions solved it
Seems like I may be missing to set some enviornment variable in my AppHarbor environment.
My test folder cannot find reference to the nunit framework. I am using NUnit 2.5.9.
Part of the build output is pasted below. Any ideas what am I missing?
Primary reference "nunit.framework".
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3245: Could not resolve this reference. Could not locate the assembly "nunit.framework". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [D:\temp\oyiirwgf.sjw\input\JeeneeTest\JeeneeTest.csproj]
For SearchPath "{HintPathFromItem}".
Considered "..\..\..\..\..\..\..\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\framework\nunit.framework.dll", but it didn't exist.
For SearchPath "{TargetFrameworkDirectory}".
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\nunit.framework.dll", but it didn't exist.
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\nunit.framework.exe", but it didn't exist.
For SearchPath "{Registry:Software\Microsoft\.NETFramework,v4.0,AssemblyFoldersEx}".
We (AppHarbor) recommend you use the NuGet Nunit package. You can either commit the /packages folder along with your code or use NuGet package restore to make the NuGet package work as part of you AppHarbor build.
Probably you added reference to NUnit, which is installed on your development PC (path points to NUnit installation folder: Program Files (x86)\NUnit 2.5.9\bin\net-2.0\framework\nunit.framework.dll). There are two options to fix this:
Install NUnit on PC where you running tests
Use a reference to local nunit.framework.dll in your tests project
I prefer second one.
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.