如何使用 VsTest.Console 运行测试列表 [英] How to run a list of tests with VsTest.Console

查看:57
本文介绍了如何使用 VsTest.Console 运行测试列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 vstest.console.exe 运行测试列表?.vsmdi 格式提供了一种指定测试列表的方法,但该格式已被弃用(?).

How can I run a list of tests using vstest.console.exe? The .vsmdi format offered a way to specify test lists, but that format is deprecated(?).

我可以在命令行上运行一个明确的测试列表,这基本上完全符合我的要求,但是如果测试的数量很大(比如几百个),那么我将耗尽命令行空间!

I can run an explicit list of tests on the command line, which essentially does exactly what I want, but if the number if tests is large (say a few hundred) then I will run out of command line space!

vstest.console MyTests.dll /Tests:Test1,Test2

有没有办法让 vstest.console.exe 运行以任何其他方式定义的列表测试?

Is there no way that I can trick vstest.console.exe into running a list of tests defined in any other way?

(强调)

注意:我不想更改测试代码,例如添加测试类别属性或更改命名方案,以便名称匹配将选择子集.我需要它来运行测试列表.

我能想到的最好的方法是在最大命令行长度内尽可能多地运行,然后重复直到设置完成,然后合并.但是,如果有某种方法可以加载旧版 vsmdi 列表或类似列表,那就容易多了.

The best I can think of is to run as many as I can fit within the max command line length, and repeat until the set is done, then merge. But if there is some way of loading a legacy vsmdi list or similar it would be a lot easier.

vstest.console MyTests.dll < testnames.txt

vstest.console MyTests.dll /Testlist:testnames.txt

推荐答案

您可以在特定格式的文本文件中列出您的测试,然后像这样将其输入到 vstest.console.exe 中.假设文件名为 mytests.orderedtest:

You can list your tests in a text file of a particular format and then feed that into vstest.console.exe like so. Assume file is called mytests.orderedtest:

vstest.console mytests.orderedtest

mytests.orderedtest 必须采用特定格式.有一种简单的方法可以从 Visual Studio 创建这样的测试,然后您可以查看内容.

The mytests.orderedtest has to be in a specific format. There's an easy way to create such a test from Visual Studio and then you can look at the contents.

首先,在 Visual Studio 中,右键单击解决方案资源管理器中的项目,然后选择添加/有序测试.这将创建一个带有漂亮 UI 的orderedtest 文件,您可以在其中添加测试.因此,从列表中选择您的测试:Test1,Test2.这将创建一个看起来像这样的文件:

First, in Visual Studio, right-click on the project in Solution Explorer, then select Add / Ordered Test. This will create an orderedtest file with a nice UI that you can add your tests. So, pick your tests from the list: Test1,Test2. That will create a file that looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
    <OrderedTest name="mytests" storage="c:\src\MyTests\MyTests.orderedtest" id="ed4d22c5-ab9a-4ebd-954f-65ac4c034338" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
  <TestLinks>
    <TestLink id="14c6766b-c22b-130a-ddb0-53d5ddd6eb1d" name="Test1" storage="..\bin\debug\MyTests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <TestLink id="24c6766b-c22b-130a-ddb0-53d5ddd6eb1d" name="Test2" storage="..\bin\debug\MyTests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </TestLinks>
</OrderedTest>

如果您要在 Visual Studio 之外手动创建,请注意,id 属性中的 GUID 很重要.这是在不同的完全限定类名之间区分具有相同名称的测试的唯一方法.即id是由namespace+class+method组成的.这篇文章解释了:http://blogs.msdn.com/b/aseemb/archive/2013/10/06/how-to-create-an-ordered-test-programmatically.aspx

If you are going to create this manually, outside of Visual Studio, note that the GUID in the id attribute is significant. It is the only way tests with the same name are differentiated across different fully-qualified class names. That is, the id is composed from namespace+class+method. This article explains it: http://blogs.msdn.com/b/aseemb/archive/2013/10/06/how-to-create-an-ordered-test-programmatically.aspx

这是一个将完全限定的方法名称转换为这些 GUID 之一的例程:

Here's an routine that will convert the fully qualified method name into one of these GUIDs:

// convert the test (<Name space name>.<class name>.<test method name>) to a GUID
static Guid GuidFromString(string data) 
{
    SHA1CryptoServiceProvider provider = new SHA1CryptoServiceProvider();
    byte[] hash = provider.ComputeHash(System.Text.Encoding.Unicode.GetBytes(data));
    byte[] toGuid = new byte[16]; 
    Array.Copy(hash, toGuid, 16);
    return new Guid(toGuid); 
}

这篇关于如何使用 VsTest.Console 运行测试列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆