如何仅在Azure Devops CI env中而非本地运行一些测试 [英] How to run some tests only in azure devops CI env but not locally

查看:88
本文介绍了如何仅在Azure Devops CI env中而非本地运行一些测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想指定一些长时间运行的c#项目xUnit测试,使其仅在azure devops CI管道中运行,而不是在本地单击Visual Studio(vs2019)中的全部运行"时运行.这种行为是否有最佳实践"?

I would like to specify some long-running c# project xUnit tests to only run in azure devops CI pipeline, but not when a click 'Run All' in Visual Studio locally (vs2019). Is there a 'best practice' for this kind of behaviour?

我试着制作一个测试播放列表,而不是在本地运行该列表而不是Run All,但这每次我添加新测试都需要更新一个或多个列表,这很容易出错.

I played around with making a test playlist and running that locally instead of Run All, but that would require updating the list (or lists) everytime i add new tests and this is error-prone.

推荐答案

FactAttribute中的Skip属性是可覆盖的-您可以创建FactWhenAttribute并让其检查环境变量

The Skip property in FactAttribute is overridable - you can make a FactWhenAttribute and have it check an environment variable

此帖子来自@Joseph伍德沃德

public sealed class IgnoreOnAppVeyorLinuxFact : FactAttribute
{
    public IgnoreOnAppVeyorLinuxFact() {
        if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && IsAppVeyor()) {
            Skip = "Ignore on Linux when run via AppVeyor";
        }
    }

    private static bool IsAppVeyor()
        => Environment.GetEnvironmentVariable("APPVEYOR") != null;
}

这篇关于如何仅在Azure Devops CI env中而非本地运行一些测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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