Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running unit tests with .NET Core MSTest: "The following TestContainer was not found..."

I've searched high and low and can't find answer to this Exception. This question is the main one to come up when I search, but it doesn't address this issue.

[7/8/2018 6:22:22 PM Informational] Executing test method 'CoreScraper.FlyerScraper.GetAllCurrentFlyers'
[7/8/2018 6:22:22 PM Error] System.InvalidOperationException: The following TestContainer was not found 'C:\Users\Username\Documents\Visual Studio 2017\Projects\ProductApp\CoreScraper\bin\Debug\netcoreapp2.0\CoreScraper.dll'
   at Microsoft.VisualStudio.TestWindow.Controller.TestContainerProvider.<GetTestContainerAsync>d__61.MoveNext()

"CoreScraper" is the name of the project. When I look in that ...\netcoreapp2.0\ folder, the CoreScraper.dll is definitely in there. I am running the test by right-clicking in the test method and selecting "Run Tests". The test ran fine the very first time I ran it, but it has given me this error ever since. I've closed out of Visual Studio and reopened, deleted the contents of bin\, cleaned and rebuilt the project, etc.

like image 894
Josh Withee Avatar asked Jul 10 '18 01:07

Josh Withee


People also ask

Does MSTest work with .NET core?

In this article, I will explain about the unit test in asp.net core using MSTest. There are three different test frameworks which are supported by the unit test with asp.net core: MSTest, xUnit, and NUnit, which allow us to test our code in a consistent way.


2 Answers

What worked for me:

Delete folders inside .vs folder.

But you still can't delete that folder ?

Probably because of Live Unit Testing, testhost.exe or testhost.x86.exe process is the cause.

like image 141
aybe Avatar answered Oct 03 '22 20:10

aybe


The problem was that the NuGet package Microsoft.NET.Test.Sdk was not installed. Installing this package in the project via the NuGet Package Manager solved the problem.

This wasn't intuitive to me since I have another unit test project that runs fine without the Microsoft.NET.Test.Sdk package, but that project is .NET Framework 4.6.2.

like image 44
Josh Withee Avatar answered Oct 03 '22 20:10

Josh Withee