VSTest: A testsettings file or a runsettings with a ForcedLegacyMode set to true is not supported with the MSTest V2 Adapter. No test is available
Asked Answered
E

2

16

How to use .testsettings file running unit tests via vstest.console.exe? I created empty visual studio solution, created empty unit test project, added Local.testsettings file as a solution item.

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {

    }
}

enter image description here

<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local" id="1109524d-9809-4423-b7fa-fad429ebfd8d" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
  <Description>These are default test settings for a local test run.</Description>
  <Deployment enabled="false" />
  <Execution hostProcessPlatform="MSIL">
    <TestTypeSpecific>
      <UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
        <AssemblyResolution>
          <TestDirectory useLoadContext="true" />
        </AssemblyResolution>
      </UnitTestRunConfig>
    </TestTypeSpecific>
    <AgentRule name="LocalMachineDefaultRole">
    </AgentRule>
  </Execution>
  <Properties />
</TestSettings>

Everything is ok when I run my tests with following command:

>> "[path to vstest]/vstest.console.exe" [path to project]\UnitTestProject1.dll

The command below gives an error.

"[path to vstest]/vstest.console.exe" [path to project]\UnitTestProject1.dll /Settings:[path to settings file]\Local.testsettings

Warning : A testsettings file or a runsettings with a ForcedLegacyMode set to true is not supported with the MSTest V2 Adapter. No test is available in [path]\UnitTestProject1.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

Additionally, path to test adapters can be specified using /TestAdapterPath command. Example /TestAdapterPath:.

So I added /TestAdapterPath:[project path/bin/Debug] parameter. The Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll with discoverer and executor is situated here. But I got the same error without the last sentence about specifying test adapter.

I was wondering if someone could solve this problem.

Experientialism answered 10/4, 2018 at 16:2 Comment(0)
E
17

The solution is to use Microsoft.VisualStudio.QualityTools.UnitTestFramework instead of Microsoft.VisualStudio.TestPlatform.TestFramework which is added to your unit test project by Visual Studio by default. So you can remove two packages via NuGet. You should delete MSTest.TestAdapter and MSTest.TestFramework and install Microsoft.VisualStudio.QualityTools.UnitTestFramework.Updated. Your unit tests will be discovered after these steps.

Also you can read the following useful article about test framework MSTest V2.

Experientialism answered 11/4, 2018 at 11:9 Comment(3)
Your advice doesn't appear to be in the article you cite from Microsoft. Where are you getting that information?Effendi
@DanEsparza This is article just a useful information and it doesn't contains the solution.Experientialism
thanks! that put an end to the most boring rabbit hole ever :)Imponderabilia
C
43

I had the similar problem and I have resolved it the following way:

  1. Go to Test -> Test Settings

  2. Uncheck the \..\..projectTestSettings.testsettings file

  3. Run the tests again

Clingy answered 1/11, 2018 at 20:3 Comment(3)
I did the same. But after that my unit test crashes before it enters the test case.Stepchild
@apb_developer, probably the method provided in the answer is helpful, but it was something else that caused the tast to crash, for example, the contents of provided file. In my case, I provided .runsettings file and therefore was able to set ForceLegacyMode (inside MSTest section) to false. Surely, i had to check the new file instead of the previous default one.Unmeant
this is the solutionGusman
E
17

The solution is to use Microsoft.VisualStudio.QualityTools.UnitTestFramework instead of Microsoft.VisualStudio.TestPlatform.TestFramework which is added to your unit test project by Visual Studio by default. So you can remove two packages via NuGet. You should delete MSTest.TestAdapter and MSTest.TestFramework and install Microsoft.VisualStudio.QualityTools.UnitTestFramework.Updated. Your unit tests will be discovered after these steps.

Also you can read the following useful article about test framework MSTest V2.

Experientialism answered 11/4, 2018 at 11:9 Comment(3)
Your advice doesn't appear to be in the article you cite from Microsoft. Where are you getting that information?Effendi
@DanEsparza This is article just a useful information and it doesn't contains the solution.Experientialism
thanks! that put an end to the most boring rabbit hole ever :)Imponderabilia

© 2022 - 2024 — McMap. All rights reserved.