Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 278
Joseph Katzman Avatar asked Apr 10 '18 16:04

Joseph Katzman


People also ask

How do I create a Testsettings file?

Create a test settings file. In Solution Explorer, right-click Solution Items, point to Add, and then choose New Item. The Add New Item dialog box appears. In the Installed Templates pane, choose Test Settings.

How can a test be configured in MSTest v2?

To create a test, you have to write a method with the attribute [TestAttribute] in a class decorated with the [TestClass] attribute. The TestClass attribute may seem superfluous, but we'll see in another post its importance 😃 You can use the methods of the Assert class to validate the behavior of the method under test.

What is VSTest console exe?

VSTest. Console.exe is the command-line tool to run tests. You can specify several options in any order on the command line. These options are listed in General command-line options. The MSTest adapter in Visual Studio also works in legacy mode (equivalent to running tests with mstest.exe) for compatibility.


1 Answers

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

like image 56
Maheswari Ramalingam Avatar answered Sep 22 '22 16:09

Maheswari Ramalingam