Reputation: 4602
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 and flipping the framework version back to .Net 4.5.1 makes them run again on the server.
I am getting the following error:
No test found. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
I have reproduced the problem in a simpler setup:
Upvotes: 177
Views: 154864
Reputation: 266
For me, adding something like this in your project's .csproj file worked:
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>WhateverFileName.Tests, PublicKey=213456789</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
Upvotes: 0
Reputation: 1045
My build was not finding the tests either. My setup and solution for finding the tests are as follows.
I use Azure Devops 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 Azure Devops 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.
Upvotes: 77
Reputation: 93
I fixed this by issue in VS 2022 with .net 4.8 and the simplest way - installed NUnit and NUnitTestAdapter with NuGet
Upvotes: 0
Reputation: 117
In my case I was missing to add [Fact] decorator on the tests to indicate it is Test method. It ran awesomely after including this.
public class PieControllerTests
{
[Fact]
public void List_EmptyCategory_ReturnsAllPies()
{
// Arrange
var mockPieRepository = RepositoryMocks.GetPieRepository();
var mockCategoryRepository = RepositoryMocks.GetCategoryRepository();
var pieController = new PieController(mockPieRepository.Object, mockCategoryRepository.Object);
// Act
var result = pieController.List("");
// Assert
var viewResult = Assert.IsType<ViewResult>(result);
var pieListViewModel = Assert.IsAssignableFrom<PieListViewModel>(viewResult.ViewData.Model);
Assert.Equal(10, pieListViewModel.Pies.Count());
}
}
Upvotes: 1
Reputation: 1053
Make sure that your test adapter .dll
file is located in the directory alongside the *.Test.dll
files you intend to test. In my case, I needed to configure the pathtoCustomTestAdapters
parameter of the VSTest@3
task to point to the directory where the test adapter .dll
was copied. In my scenario, this directory was $(Agent.BuildDirectory)\References\Client.Debug\
. This necessity arises from the specific logic of my solution, where nearly all generated dll
s, including the test adapter's dll
, are copied to this designated directory.
Upvotes: 0
Reputation: 35695
In my particular case I had loaded the same file twice.
<ItemGroup>
<Compile Include="TitleBlockSizerTests.cs" />
<Compile Include="TitleBlock\TitleBlockSizerTests.cs" /> Notice how this file is listed twice?
</ItemGroup>
Notice how the same file is included twice? Once that was removed, the tests ran fine.
Upvotes: 1
Reputation: 273
With net6.0 targetFramework I added these packages to .csproj-file:
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
after which it started working. earlier versions may not be compatible with net6.0.
Do check the latest versions for the packages appropiate for your .NET version for example from nuget.org
Upvotes: 6
Reputation: 1811
I got this error because I had accidentally changed the Tests.cs file Compile action to 'None'.
Upvotes: 1
Reputation: 293
With NUnit3, in most cases all I had to do was to add
<PackageReference Include="NUnit3TestAdapter" Version="4.x.x" />
However in some of .NET Framework 4.7.2 SDK-style tests projects that wasn't enough.
The issue was with PlatformTarget
project property. If unspecified it defaults to AnyCPU
, however NUnit seems to always fail with
No test is available in Foo.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
if it was left unspecified.
So, besides the PackageReference, I had to either:
<PlatformTarget>x86</PlatformTarget>
.<PlatformTarget>AnyCPU</PlatformTarget>
(even though it is AnyCPU
if unspecified) and then in Test tab set "Processor Architecture for AnyCPU Projects" to "x86".
Upvotes: 1
Reputation: 2596
If your solution only has one test file, check it has the .cs
file extension.
I used the dotnet
command to create a new test project for myself.
I hastily renamed the generated class (UnitTest1.cs
) without the .cs
file extension.
This is similar to @Jared-Beach's scenario: obviously no tests were found via the IDE nor the command line. Beyond the first three words, the rest of the error message will point you in the wrong direction.
Upvotes: 0
Reputation: 2132
One more random thing to do is to add the file xunit.runner.json
.
Example configuration:
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"appDomain": "ifAvailable",
"shadowCopy": false,
"parallelizeTestCollections": false,
"maxParallelThreads": 1
}
Don't forget to include it in the project:
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
In my case, this was the magical remedy.
Upvotes: 1
Reputation: 5531
For me the problem was an old reference to Microsoft.VisualStudio.TestPlatform
. You don't need an explicit reference to this package because MSTest.TestFramework
has a transitive reference to this package with a correct version.
Upvotes: 0
Reputation: 233347
I've recently run into this issue as well, and I can with some confidence state that it's not one covered by any of the other answers here.
I've recently been writing some F# modules that (for reasons) have signature files. Again, for reasons, I've had to put unit tests into the same module.
When an F# source file is 'covered' by a signature file, only the declared values are exported. Thus, you have to explicitly declare each and every test in the signature file as well, otherwise you'll get the error message in the OP.
Upvotes: 1
Reputation: 51
I installed nunit3adapter
package and it worked for me from my test log:
-->(NUnit3TestExecutor discovered 6 of 6 NUnit test cases using Current Discovery mode, Non-Explicit run)
Upvotes: 4
Reputation: 71
I have just been through this issue. It seems there may be a lot of causes for it. In my case, I was trying some codes and due to that, I renamed the project, removed it.. added it again... and all of a sudden, my single test stopped working and the Test output window was showing this error: "No test found. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again" The Debug output was showing errors related to the platform: "Following dll(s) do not match current settings, which are .netframework , version 4.5 and platform X86."
Using VS 2019 v 16.8.0 Test project on .NET Framework 4.8 Configured to Debug/Any CPU
After trying a bunch of things, the solution was
This worked for me, hope it works for you.
Upvotes: 2
Reputation: 5869
This question is obviously being found by people with a range of scenarios, my answer will cover running XUnit tests on a .NET Core project using build pipeline on Azure DevOps but may help others too.
otherConsoleOptions: '/framework:.NETCoreApp,Version=v3.1'
to the inputs
of your VSTest@2
step (with the version number set to whatever version of .NET Core you are using). See this documentation for more info.failOnMinTestsNotRun: true
so that the build pipeline will report a failure if zero tests are run.The library 'hostpolicy.dll' required to execute the application was not found
. You can solve this by changing your filter from the default **\*test*.dll
to **\*test.dll
(note the removed asterisk), or some other pattern which will match your test project's DLL. The reason for this is that XUnit places a file called testhost.dll
in the output directory, as explained in this github issue.If you are using the older pipelines which do not use yaml, the same options should be available. This answer covers adding the framework, I assume there will also be an option to "Fail the task if a minimum number of tests are not run" or something similar.
Upvotes: 5
Reputation: 3836
In my case, I had to:
Convert test project to netcore 2.0 (was netstandard 2.0)
Add nuget package xunit.runner.visualstudio
Reference: http://www.neekgreen.com/2017/11/20/xunit-no-test-is-available/
Upvotes: 60
Reputation: 1559
I solved this issue by installing NUnit3TestAdapter NuGet into my project (https://www.nuget.org/packages/NUnit3TestAdapter/).
dotnet add package NUnit3TestAdapter --version 3.17.0
My .csproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="RestSharp" Version="106.11.7" />
</ItemGroup>
</Project>
Upvotes: 4
Reputation: 118
I faced the similar issue when tried nUnit in VS 2017 and it's not a core project.
Installing NUnit3TestAdapter
fixed the issue.
Upvotes: 4
Reputation: 384
I fixed this problem by reinstalling all testing related NuGet packages for the project:
Xunit
, Xunit.runner.vistualstudio
, Microsoft.Net.Test.Sdk
Upvotes: 12
Reputation: 71
Upvotes: 7
Reputation: 889
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"
Upvotes: 2
Reputation: 641
Try running vstest.console.exe
with --diag:diag.txt
and inspect the output. For me it was DLL load failures for test adapters from my working directory:
TpTrace Information: 0 : 14976, 1, 2020/03/10, 15:34:22.120, 57158093583, vstest.console.exe, AssemblyResolver.OnResolve: Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter: Failed to load assembly. Reason:System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Directory\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///C:\Directory\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll' ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
I worked around this by adding <loadFromRemoteSources enabled="true"/>
under <runtime>
in vstest.console.exe.config
Upvotes: 3
Reputation: 701
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
Upvotes: 4
Reputation: 3342
In my case the tests were discovered but running resulted in "Test not Available..." and the (in)famous: "Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again."
the error was independent of Visual Studio (tested from dotnet CLI tools and nearly naked UNit test) and it was only when targeting .NET 4.7.1. dotnetcore app works fine.
also running tests with the Nuint3 CLI
nunit3-console.exe Tests.csproj
shows the error:
"Either assembly contains no tests or proper test driver has not been found."
the error was because the test-adapter could not be found on a (mapped) network drive or share and was solved by copy it locally and rerun.
Upvotes: 2
Reputation: 1
After add the TestAdapterPath in the commander, it's worked for me:
vstest.console.exe Xom.Gci.Lvf.FileParserInvoker.UnitTests.dll /TestAdapterPath:"C:\****\****\{SolutionFolder}"
Upvotes: 0
Reputation: 83
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.
Upvotes: 1
Reputation: 522
This error can happen for async tests if you have the wrong return type. The return type should be Task, and not void.
Upvotes: 3
Reputation: 1103
In my case Reinstalling Nunit3 Adapter, Deleting temp folders, Changing architecture and nothing worked. Its because of the Daemon Resharper caused the problem.
Add or Remove Programs> Find Resharper > Repair > Install again > Restart VS
That resolves the issues.
Upvotes: 0
Reputation: 7356
I'll throw my solution onto the heap. In my case, I am adding a couple of projects to an existing solution along with Test projects for them. We're using MSTest. There was a previous UnitTest.testsettings file enabled on the solution that was causing compatibility issues.
Clicking on the settings file removed the check and the test run was successful for my tests.
Upvotes: 6