2010-04-30 67 views
1

是否可以在運行時禁用選定的自動化測試?在運行時禁用選定的自動化測試

我使用VSTS和犀牛製品,並且必須安裝需要外部扶養一些intergation測試(MQ)。並非我所有團隊的開發人員都已安裝。

目前所有需要MQ測試從如果安裝了MQ,檢查一個基類繼承,如果不設置測試結果尚無定論。這可以起到阻止測試運行的作用,但會將測試運行標記爲不合格,並可能隱藏其他故障。

任何想法?

回答

0

最後得到了一個弄清楚這一點,這是我做的。

在我的每一個測試類(或如果只有在類測試少數需要MQ方法)有MQ依賴關係的添加以下的類(或方法)decleration

#if !RunMQTests 
    [Ignore] 
#endif 

這禁用測試,除非您已將條件比較符號RunMQTests解密,此符號未在項目文件中定義,因此默認情況下禁用測試。

爲了使這些測試具有了開發商要記住,如果他們已經安裝了MQ和添加或刪除條件compalation符號,我創建了一個自定義生成的任務,將告訴我們,如果安裝了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" /> 

並調用在BeforeBuild目標的新的自定義任務,並設置條件compalation符號如果這臺機器已經安裝了MQ。

<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集成測試,而不會失敗用戶的測試運行。

相關問題