Home > Net >  Visual Studio 2019 UnitTest not running
Visual Studio 2019 UnitTest not running

Time:08-09

I'm using Microsoft Visual Studio Community 2019 Version 16.11.8

I created a C# Windows Forms-App (.NET Framework) and now trying to add a UnitTest for it. For the beginning I tryed the first steps from tutorials in the Internet:

  • Add new MSTest-Project
  • It automatically creates a first test-class and I added an Assert.IsTrue(true) to it:
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    namespace MyFirstUnitTest
    {
        [TestClass]
        public class UnitTest1
        {
            [TestMethod]
            public void TestMethod1()
            {
                Assert.IsTrue(true);
            }
        }
    }

If I now run the test in Test-Explorer, the test keeps in "not tested" state. If I take a look in the Output window of Tests I see the Following exception:

     ========== Testermittlung wird gestartet ==========
     ========== Testermittlung abgeschlossen: 1 Tests in "2,6 Sek." gefunden ==========
     ========== Testlauf wird gestartet ==========
     Ausnahme beim Aufrufen von Executor "executor://mstestadapter/v2": Could not find file 'C:\Users\xxxxx\Documents\Projects\MyFirstUnitTest\TestResults\Deploy_xxxxxxx 2022-08-04 21_06_19'.
     Stapelüberwachung:
        at System.IO.FileSystem.CreateDirectory(String fullPath, Byte[] securityDescriptor)
        at System.IO.Directory.CreateDirectory(String path)
        at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities.FileUtility.CreateDirectoryIfNotExists(String directory)
        at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities.DeploymentUtilityBase.CreateDeploymentDirectories(IRunContext runContext)
        at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestDeployment.Deploy(IEnumerable`1 tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.RunTests(IEnumerable`1 tests, IRunContext runContext, IFrameworkHandle frameworkHandle, TestRunCancellationToken runCancellationToken)
        at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.MSTestExecutor.RunTests(IEnumerable`1 tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithTests.InvokeExecutor(LazyExtension`2 executor, Tuple`2 executorUri, RunContext runContext, IFrameworkHandle frameworkHandle)
        at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(IEnumerable`1 executorUriExtensionMap, Int64 totalTests)

What can I do to get the UnitTest run? The folder its looking for really not exists. Who should create the folder "TestResults" normally?

Side Info:

  • I tryed to run Visual Studio with Administrator rights
  • I turned of my firewall
  • I tryed to create the Test-Project with target Platform .NET core 3.1 and with .NET 5.0
  • I restartet Visual Studio multiple times Nothing of all these changed anything, I always get the error Message above.

Testproject is using following NuGet Packeges:

  • coverlet.collector V3.1.2
  • Microsoft.NET-TestSdk V17.2.0
  • MSTest.TestAdapter V2.2.10
  • MSTest.TestFramework V 2.2.10

CodePudding user response:

I found the problem: The ransomware-protection of windows prohibited the writing of new files for MSTest. I set it to allow-list, now it works :)

  • Related