问题描述
如何通过vstest.console.exe
使用.testsettings
文件运行单元测试?我创建了空的Visual Studio解决方案,创建了空的单元测试项目,并添加了Local.testsettings
文件作为解决方案.
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()
{
}
}
<?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
以下命令给出错误.
"[path to vstest]/vstest.console.exe" [path to project]\UnitTestProject1.dll /Settings:[path to settings file]\Local.testsettings
此外,可以使用以下命令指定测试适配器的路径/TestAdapterPath命令.例子/TestAdapterPath:.
Additionally, path to test adapters can be specified using /TestAdapterPath command. Example /TestAdapterPath:.
所以我添加了/TestAdapterPath:[project path/bin/Debug]
参数.带有发现者和执行者的Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll
位于此处.但是没有指定测试适配器的最后一句话,我还是遇到了同样的错误.
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.
推荐答案
解决方案是使用Microsoft.VisualStudio.QualityTools.UnitTestFramework
代替Microsoft.VisualStudio.TestPlatform.TestFramework
,默认情况下,Visual Studio已将Microsoft.VisualStudio.TestPlatform.TestFramework
添加到您的单元测试项目中.因此,您可以通过NuGet
删除两个软件包.您应该删除MSTest.TestAdapter
和MSTest.TestFramework
并安装Microsoft.VisualStudio.QualityTools.UnitTestFramework.Updated
.这些步骤之后,将发现您的单元测试.
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.
您还可以阅读以下有关测试框架的有用文章 MSTest V2 .
Also you can read the following useful article about test framework MSTest V2.
这篇关于VSTest:MSTest V2适配器不支持testsettings文件或ForcedLegacyMode设置为true的运行设置.没有可用的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!