简体   繁体   English

是否可以在TestCases和Microsoft Test Manager中使用.testsettings文件?

[英]Is there an alternative for using a .testsettings file with TestCases and Microsoft Test Manager?

We have a peculiar situation here that is causing our automated tests to fail on a newly created lab environment, using TFS 2012. 我们这里有一个特殊情况,这导致我们使用TFS 2012在新创建的实验室环境中自动测试失败。

We've always had a bunch of 'unit' tests that tested our DAL code, which in turn uses the Enterprise Library Data Application Block to perform operations on the database. 我们总是有很多测试DAL代码的“单元”测试,这些代码又使用企业库数据应用程序块对数据库执行操作。 This was setup quite a few years ago, to enable our clients to choose either SqlServer or Oracle databases alongside our product, taking advantage of the DatabaseFactory class and all the supporting generic interfaces and classes in the entlib.data. 该设置是在几年前进行的,以使我们的客户可以选择SqlServer或Oracle数据库以及我们的产品,从而利用DatabaseFactory类以及entlib.data中所有支持的通用接口和类。 I mentioned 'unit' like this because these are actually not pure unit tests but integration ones, seeing as they require a real database to work. 我之所以这样说“单元”,是因为它们实际上不是纯粹的单元测试,而是集成的,因为它们需要一个真正的数据库才能工作。

To test the same SQL code against both databases, we maintain two separate .config files inside a 'Resources' folder in our TFS project branch, pointing to our test databases: 为了针对两个数据库测试相同的SQL代码,我们在TFS项目分支的“资源”文件夹中维护两个单独的.config文件,它们指向我们的测试数据库:

  • Resources\\SqlServer\\ConnectionStrings.config (SqlServer specific connection strings) Resources\\SqlServer\\ConnectionStrings.config (特定于SqlServer的连接字符串)
  • Resources\\Oracle\\ConnectionStrings.config (Oracle specific connection strings) Resources\\Oracle\\ConnectionStrings.config (Oracle特定的连接字符串)

In the root Resources folder, there are two accompanying .testsettings files, responsible for deploying files specific to each database: 在根Resources文件夹中,有两个随附的.testsettings文件,它们负责部署特定于每个数据库的文件:

  • Resources\\SqlServer.testsettings (which deploys the SqlServer\\ConnectionStrings.config file) Resources\\SqlServer.testsettings (用于部署SqlServer \\ ConnectionStrings.config文件)
  • Resources\\Oracle.testsettings (which deploys the Oracle\\ConnectionStrings.config file) Resources\\Oracle.testsettings (用于部署Oracle \\ ConnectionStrings.config文件)

Since the whole structure is in source control, the testsettings is able to find the .config files by using relative paths, allowing us to test everything without having to setup parameters manually. 由于整个结构都在源代码控制中,因此测试设置能够使用相对路径查找.config文件,从而使我们能够测试所有内容,而无需手动设置参数。 On devs machines, we always select the SqlServer.testsettings file when running the tests, so that they don't need to have the whole oracle environment installed to validate their changes before checking in the code. 在devs机器上,我们总是在运行测试时选择SqlServer.testsettings文件,这样,在签入代码之前,无需安装整个oracle环境来验证其更改。 The Oracle side of the validation always occurred in our build process, where we actually test every method twice: first using the same SqlServer.testsettings used by the developers, and then using the Oracle.testsettings . 验证的Oracle端始终发生在我们的构建过程中,在该过程中,我们实际上对每种方法进行了两次测试:首先使用开发人员使用的相同SqlServer.testsettings ,然后使用Oracle.testsettings

This way, we can setup our test assemblies' app.configs to redirect the connectionStrings node to an external file, like this: 这样,我们可以设置测试程序集的app.configs来将connectionStrings节点重定向到外部文件,如下所示:

<configuration>
  <connectionStrings configSource="ConnectionStrings.config"/>
  ...

When the tests are run, mstest copies the adequate ConnectionStrings.config file to the test's working folder, based on which .testsettings was used to initiate the run. 运行测试时,mstest会根据用来启动运行的.testsettings将足够的ConnectionStrings.config文件复制到测试的工作文件夹中。

This was working fine until today, when I discovered that tests started through Microsoft Test Manager ignore the Visual Studio .testsettings files . 直到今天,它一直运行良好,直到我发现通过Microsoft测试管理器启动的测试都忽略了Visual Studio .testsettings文件 Now I'm trying to run these same tests in our lab environment but the ConnectionStrings.config files are not deployed (understandably) and the tests fail. 现在,我试图在我们的实验室环境中运行这些相同的测试,但是未部署ConnectionStrings.config文件(可以理解),并且测试失败。

How can we achieve this without using .testsettings files? 在不使用.testsettings文件的情况下,如何实现这一目标? After having huge headaches trying to setup oracle correctly in our new x64 build server, we disabled Oracle tests in the build definition. 在尝试在新的x64构建服务器中正确设置oracle之后,我们在构建定义中禁用了Oracle测试。 Now that we started setting up our lab environment, we thought about having one of the machines in it configured with our whole system using Oracle, enabling us to again run these 'unit tests' with oracle-specific connection strings to validate our queries. 现在,我们开始设置实验室环境,我们考虑使用Oracle在其中的一台计算机上配置了整个系统,从而使我们能够再次使用特定于oracle的连接字符串运行这些“单元测试”以验证查询。 At the same time, we want to keep testing everything locally and on the build server using SqlServer also. 同时,我们希望继续使用SqlServer在本地以及在构建服务器上测试所有内容。

I think using [DeploymentItem] in this case is impossible, since it is meant for static files and not selectable, dynamic ones like our current setup. 我认为在这种情况下无法使用[DeploymentItem] ,因为它用于静态文件,而不是像我们当前设置那样的不可选择的动态文件。

Is there any equivalent to the .testsettings deployment process that we could use with TestCases inside MTM/Lab Env? 我们可以在MTM / Lab Env中与TestCases一起使用的.testsettings部署过程是否等效? On the Properties tab for our TestPlan, I can see the Automated Runs -> Test Settings option, but that only seems to allow deployment by specifying absolute paths (which will actually be resolved on the target machines). 在我们的TestPlan的Properties选项卡上,我可以看到Automated Runs -> Test Settings Runs- Automated Runs -> Test Settings选项,但这似乎只允许通过指定绝对路径进行部署(这将在目标计算机上实际解析)。 Is there a way to specify a relative path there, pointing to our ConnectionStrings.config files checked in on TFS? 有没有一种方法可以在那里指定相对路径,指向我们在TFS上签入的ConnectionStrings.config文件? Maybe yet another alternative exists that I'm missing, perhaps using multiple build configurations? 也许我还缺少另一个选择,也许使用了多个构建配置?

Create separate build configurations for each of the server types by going into Configuration Manager and click New under Active solution configurations . 通过进入配置管理器并为活动解决方案配置下的“ 新建” ,为每种服务器类型创建单独的构建配置 Edit the project file and do something like this: 编辑项目文件,然后执行以下操作:

<PropertyGroup Condition="'$(Configuration)' == 'Oracle'">
  <appConfig>App.Oracle.Config</AppConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'SQL'">
  <appConfig>App.SQL.Config</AppConfig>
</PropertyGroup>

Then ensure you have the correct connection strings in each of the config files. 然后,确保每个配置文件中都有正确的连接字符串。 You can then configure TFS to build using those build configurations. 然后,您可以配置TFS以使用那些构建配置进行构建。

More info on using PropertyGroup and Condition , MSBuild Configurations and MSBuild project properties 有关使用PropertyGroup和ConditionMSBuild配置MSBuild项目属性的更多信息

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

相关问题 用于单元测试的TestSettings网络仿真 - TestSettings Network Emulation for Unit Test 在Microsoft测试管理器中丢失测试结果 - Lost test results in Microsoft Test manager 如何使用Microsoft Test Manager在多个系统中从TFS自动化多个测试用例? - How to automate multiple test cases from TFS in multiple systems using Microsoft Test Manager? 如何使用test:unit在ruby中运行多个测试用例 - How to run multiple testcases in ruby using test:unit Microsoft测试管理器中的单元测试 - Unit-tests in Microsoft Test Manager 将xUnit / nUnit测试与Microsoft Test Manager集成 - Integrating xUnit/nUnit Tests with Microsoft Test Manager 使用.testsettings的Visual Studio 2013手动测试 - Visual Studio 2013 Manual Testing using .testsettings 如何在Microsoft测试管理器中运行测试方法(在Visual Studio中)? - How to run test methods (in Visual Studio) in Microsoft Test Manager? MSTest V2 适配器不支持 testsettings 文件或 vsmdi 文件 - A testsettings file or a vsmdi file is not supported with the MSTest V2 Adapter 是否可以在Visual Studio 2013中同时使用.testsettings和.runsettings文件? - Is there a way to use both a .testsettings and .runsettings file in Visual Studio 2013?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM