在运行时禁用选定的自动化测试

发布于 2024-08-30 16:02:03 字数 229 浏览 2 评论 0原文

是否可以在运行时禁用选定的自动化测试?

我正在使用 VSTS 和 rhino 模拟,并进行一些需要安装外部依赖项 (MQ) 的集成测试。并非我团队中的所有开发人员都安装了此软件。

目前,所有需要 MQ 的测试都继承自一个基类,该基类检查是否安装了 MQ,如果未安装,则将测试结果设置为不确定。这是有效的,因为它会停止测试运​​行,但会将测试运行标记为不成功,并且可以隐藏其他失败。

有什么想法吗?

Is is posable to disable selected automated tests at runtime?

I'm using VSTS and rhino mocks and have some intergation tests that require an external dependancy to be installed (MQ). Not all the developers on my team have this installed.

Currently all the tests that require MQ inherit from a base class that checks if MQ is installed and if is not sets the test result to inconclusive. This works as it stops the tests from running, but marks the test run as unsuccseessful and can hide other failures.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-09-06 16:02:03

终于解决了这个问题,这就是我所做的。

在我的每个具有 MQ 依赖项的测试类(或方法,如果类中只有少数测试需要 MQ)中,我将以下内容添加到类(或方法) decleration 中,

#if !RunMQTests
    [Ignore]
#endif

这将禁用测试,除非您具有条件比较符号 < code>RunMQTests 已清除,该符号未在项目文件中定义,因此默认情况下禁用测试。

为了启用这些测试,开发人员不必记住他们是否安装了 MQ 并添加或删除条件比较符号,我创建了一个自定义构建任务,该任务将告诉我们是否安装了 MQ。

/// <summary>
/// An MSBuild task that checks to see if MQ is installed on the current machine.
/// </summary>
public class IsMQInstalled : Task
{
    /* Constructors removed for brevity */

    /// <summary>Is MQ installed?</summary>
    [Output]
    public bool Installed { get; set; }

    /// <summary>The method called by MSBuild to run this task.</summary>
    /// <returns>true, task will never report failure</returns>
    public override bool Execute()
    {
        try
        {
            // this will fail with an exception if MQ isn't installed
            new MQQueueManager();
            Installed = true;
        }
        catch { /* MQ is not installed */ }

        return true;
    }
}

然后我们只需要将任务添加到测试项目文件的顶部即可将其连接到构建过程中。

<UsingTask TaskName="IsMQInstalled" AssemblyFile="..\..\References\CustomBuildTasks.dll" />

如果本机安装了 MQ,则在 BeforeBuild 目标中调用新的自定义任务并设置条件比较符号。

<Target Name="BeforeBuild">
  <IsMQInstalled>
    <Output TaskParameter="Installed" PropertyName="MQInstalled" />
  </IsMQInstalled>
  <Message Text="Is MQ installed: $(MQInstalled)" Importance="High" />
  <PropertyGroup Condition="$(MQInstalled)">
    <DefineConstants>$(DefineConstants);RunMQTests</DefineConstants>
  </PropertyGroup>
</Target>

这允许安装了 MQ 的用户运行我们的 MQ 集成测试,同时不会让未安装 MQ 的用户运行测试失败。

Finaly got aroung to figuring this out, here is what I did.

In each of my test classes (or methods if only a small number of tests in the class require MQ) that had MQ dependancies I added the following to the class (or method) decleration

#if !RunMQTests
    [Ignore]
#endif

This disables the tests unless you have the conditional compalation symbol RunMQTests decleared, this symbol is not defined in the project files so the tests are disabled by default.

To enable these tests with out developers having to remember if they have MQ installed and adding or removing the conditional compalation symbol, I created a custom build task that will tell us if MQ is installed.

/// <summary>
/// An MSBuild task that checks to see if MQ is installed on the current machine.
/// </summary>
public class IsMQInstalled : Task
{
    /* Constructors removed for brevity */

    /// <summary>Is MQ installed?</summary>
    [Output]
    public bool Installed { get; set; }

    /// <summary>The method called by MSBuild to run this task.</summary>
    /// <returns>true, task will never report failure</returns>
    public override bool Execute()
    {
        try
        {
            // this will fail with an exception if MQ isn't installed
            new MQQueueManager();
            Installed = true;
        }
        catch { /* MQ is not installed */ }

        return true;
    }
}

Then we just need to hook this up into the build process by adding the task to the top of the test project file.

<UsingTask TaskName="IsMQInstalled" AssemblyFile="..\..\References\CustomBuildTasks.dll" />

And call the new custom task in the BeforeBuild target and set the conditional compalation symbol if this machine has MQ installed.

<Target Name="BeforeBuild">
  <IsMQInstalled>
    <Output TaskParameter="Installed" PropertyName="MQInstalled" />
  </IsMQInstalled>
  <Message Text="Is MQ installed: $(MQInstalled)" Importance="High" />
  <PropertyGroup Condition="$(MQInstalled)">
    <DefineConstants>$(DefineConstants);RunMQTests</DefineConstants>
  </PropertyGroup>
</Target>

This lets users that have MQ installed to run our MQ intergration tests, while not failing test runs for users that don't.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文