Cannot add Universal project to Unit test project - c#

When i right click to add reference to my Domain project from my unit test project, I get the following error:
Any idea what might be wrong?

Related

How to exclude helper projects with "Test" in their name from unit testing?

We have a utility project named Foo.Testing.Common with helper classes for our real test projects, named things like Foo.Tests.Unit and Foo.Tests.Integration. The Common project doesn't have tests, just base classes, utility methods and the like. It references XUnit so I can use Xunit.Abstractions.
How can we avoid seeing errors like the one below when we run all tests, either via .net command line or VS Test Explorer? The below error appears in VS Test Output during test discovery, for example.
No test is available in C:\Foo.Testing.Common\bin\Debug\netcoreapp3.1\Foo.Testing.Common.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException...
I assume the test process is matching on test to find test projects and then throws an error if one of those projects has no tests. Or maybe it's looking for projects that reference any xunit packages?
We could just rename the project, but is there a different way? Would like to avoid passing a list of specific test projects to the command line just to avoid the "no tests found" warnings. That is, dotnet test should just work.
Update: I've also tried referencing just xunit.abstractions and xunit.extensibility.core rather than the main xunit package, but the Common project still gets recognized as a test project.
Also tried setting IsTestProject to false in the project properties.
In order to skip Foo.Testing.Common you can set IsTestProject property to false in Foo.Testing.Common.csproj:
<PropertyGroup>
<IsTestProject>false</IsTestProject>
</PropertyGroup>

Castle Windsor - FileNotFoundException in Unit Tests

I’ve inherited an ASP.Net web application comprising of VB.Net projects. I’ve added a C# project to the solution, which references several of the VB.Net projects.
The application uses Castle Windsor as a DI container and dependencies are registered in one of the VB.Net projects.
In that VB.Net project. to avoid circular references, I use the “FromAssemblyNamed”, method to register the dependencies that are defined in my C# project:
container.Register(Classes.FromAssemblyNamed("x.y.z.TLBusinessLayerV2").BasedOn(Of IService).WithService.FromInterface().Configure(Function(c) c.LifeStyle.Transient))
This is working fine when I run the application.
However, there is an existing Unit Test project. In that I have added a reference to my C# assembly.
When I run all of the tests, some of the tests fail when they hit the code above with the following exception:
System.IO.FileNotFoundException: Could not load file or assembly x.y.z.TLBusinessLayerV2' or one of its dependencies. The system cannot find the file specified.
All of the assemblies referenced by the C# Assembly are also referenced by the Unit Test project.
The Target CPU for the VB.Net project, C# project and Unit Test project are all set to x86.
If I then run one of the failed tests individually, the test passes.
Q. Why are the Tests failing when I run them all?
Any help much appreciated.
The solution to this issue is to add a dummy class to the Unit Test project, that references a class in the assembly (loaded in "Classes.FromAssemblyNamed"). Something like:
Public Class DummyDependencies
Private Xyz As Object = GetType(<name of a class in target assembly>)
End Class
This appears to enforce the reference to the assembly.

C# Unit Test Project in Visual Studio 2013 only showing coverage for Unit Tests.

I created a new unit test project in Visual Studio and added the project under test to the references.
The test methods themselves create an object of the class under test and calls a method in that class. I hit F12 on the class name or method name in the test and it brings me to class itself. It also throws errors when I remove the reference to the project.
But when I run the code coverage I only see the test.dll and coverage of 100%. And there's no project.dll in the test\bin folder.
Has anyone any ideas why it may not be building the project.dll ?

Compilation error - when adding private accessors to a C# unit test project

I have a C# project (wpf) in VS 2010.
I added a unit test project.
Everything was OK untill I've added private accessor to the project.
Now the unit tests project isn't compiling and I get the following error:
collection was modified enumeration operation may not execute
Without any direction to a specific location.
Does anyone know what can be the reason?

Unit Test Organization

I'm using Nunit for unit testing, and added another project called "Unit Testing" to my current solution. I referenced Nunit, and changed the Namespace to the same namespace used in the main project.
I can't seem to figure out how to get access to all the classes, files, etc in the main project. Is there something I have to do to link two projects?
Did you add a project reference to your main project? Right click on your Unit Test project --> add reference --> project --> select your Main Project and add it
In your "Unit Testing" project, you just need to add a reference to the main project you want to test, just like you added the reference to NUnit.
You need to add a reference to the project like you would if you were linking any project that were held in the same Solution file.

Categories

Resources