简体   繁体   English

在Specflow测试中使用tfs访问令牌

[英]Using tfs access token in specflow tests

I'm asking this just to see if it is possible to run specflow test using a user credential Token to access tfs(TestCase) data. 我问这个问题只是为了看看是否有可能使用用户凭证令牌运行Specflow测试来访问tfs(TestCase)数据。

The context: We have CI/CD pipeline in place to run over 19K Specflow tests synchronized to TFS using specsync. 上下文:我们拥有CI / CD管道,可以运行使用specsync同步到TFS的19K Specflow测试。 Most of our tests are data-driven using Scenario Outline . 我们的大多数测试都是使用Scenario Outline进行数据驱动的。 In our Release Management pipeline, we setup test runs to be performed on multiple tests machines. 在发布管理管道中,我们设置要在多台测试计算机上执行的测试运行。 But we need to cache a user credentials to the tfs collection/project in each machine in order to have the tests to pick up the test data. 但是我们需要在每台机器上将用户凭据缓存到tfs集合/项目中,以便进行测试以获取测试数据。

The Issue: Many times, our test failed with this output: 问题:很多时候,我们的测试失败,并显示以下输出:

  • The unit test adapter failed to connect to the data source or to read the data. 单元测试适配器无法连接到数据源或读取数据。 For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" ( http://go.microsoft.com/fwlink/?LinkId=62412 ) in the MSDN Library. 有关解决此错误的详细信息,请参阅MSDN Library中的“对数据驱动的单元测试进行故障排除”( http://go.microsoft.com/fwlink/?LinkId=62412 )。 Error details: Unable to find the requested .Net Framework Data Provider. 错误详细信息:无法找到请求的.Net Framework数据提供程序。 It may not be installed.* 它可能没有安装。*

The failure is because the tfs access credentials are no longer good for reasons such as the password has changed or the user is no longer valid, etc. Therefore, we need to connect to each machine(more than 10) and reset tfs access credentials. 失败是因为tfs访问凭据由于密码更改或用户不再有效等原因而不再有效。因此,我们需要连接到每台机器(超过10个)并重置tfs访问凭据。

The requirement: Is there a way to embed a tfs tokenized credentials into the specflow tests(Feature files) or a config file so that the data source access is transparent for the test runs? 要求:是否有一种方法可以将tfs标记化的凭据嵌入到specflow测试(功能文件)或配置文件中,以便对测试运行透明地访问数据源?

BR BR

Generally, you can use personal access tokens (PAT) for connecting to TFS (see this for details), but I am not aware for any way passing this in for the TestCase data source. 一般情况下,你可以使用个人访问令牌(PAT),用于连接到TFS(见的详细信息),但我不知道任何方式传递这在TestCase的数据源。

As in your case the test method is generated by SpecSync, you can configure SpecSync to embed the test data to the generated method instead of sourcing them from TFS. 与您的情况一样,测试方法是由SpecSync生成的,您可以将SpecSync配置为将测试数据嵌​​入到生成的方法中,而不是从TFS采购它们。

In SpecSync v1.*, this can be done by specifying a merged-examples parameter to the SpecSync plugin registration in the App.config file, like this: 在SpecSync v1。*中,可以通过在App.config文件中为SpecSync插件注册指定一个merged-examples参数来完成此操作,如下所示:

<add name="SpecSync.MTM" type="Generator" parameters="merged-examples" />

From SpecSync v2 (currently in pre-release state), this will be the default behavior anyway, but you can change it in the specsync.json config file: 从SpecSync v2(当前处于预发布状态)开始,这将始终是默认行为,但是您可以在specsync.json配置文件中进行更改:

{
  ...
  "specFlow": {
    "scenarioOutlineAutomationWrappers": "iterateThroughExamples"
  },
  ...
}

(Here iterateThroughExamples uses the embedded test data (default) and useTestCaseData would get the data from TFS.) (这里iterateThroughExamples使用嵌入式测试数据(默认),而useTestCaseData将从TFS获取数据。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM