I am in the process of upgrading our existing solution to .Net 4.6.1 and have been unable to get our unit tests to run during a server build. Locally they run as expected an
My build was not finding the tests either. My setup and solution for finding the tests are as follows.
I use VSTS (Visual Studio Team Services) and have a build that is configured to refresh the NUGET packages on every build. I am using NUnit and found that running the following NUGET command (from the package manager console in Visual Studio) to add NUnitTestAdapter library to my test project and the checking in the packages.config made the tests run in my VSTS build.
Install-Package NUnitTestAdapter
As Maurice mentions in the Comment to this post for NUnit3 use the following NUGET package (Look for other utils on the link. i.e: dotnet CLI and Paket CLI)
Install-Package NUnit3TestAdapter
Hope this helps.
I fixed this by issue in VS 2017 & 4.6.2 test project with the following steps:
If you are running your tests inside docker using multistage building and tests aren't found. Make sure you copy all files not only project files like below Dockerfile section.
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["MainProject/FirstApp.csproj", "MainProject/"]
COPY ["TestProject/*", "TestProject/"]
RUN dotnet restore "TestProject/TestProject.csproj"
RUN dotnet build "TestProject/TestProject.csproj" -c Release
RUN dotnet test "TestProject/TestProject.csproj" -c Release
I use MSTest.
I installed from Nuget the latest version of MSTest.TestFramework and replaced OOB Remove references to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
Then Installed from neget the latest version of Microsoft.TestPlatform
It allowed me to run test with a command:
".\packages\Microsoft.TestPlatform.16.6.1\tools\net451\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" "UnitTestProject1\bin\Debug\UnitTestProject1.dll" /logger:trx
But I got the same error. The root cause of the error that I didn't specify a test adapter which parses the assembly and finds tests.
Solution:
Install a nuget package "MSTest.TestAdapter"
Specify a test adapter in the end of a command:
/TestAdapterPath:".\packages\MSTest.TestAdapter.2.1.2\build_common"
Found a way! Probably not the most orthodox but it did helped me out in a hurry:
I don't think is anything particular with the version, but updating it certainly cleans whatever reference is bad in the solution/project.