您可以将XUnit测试标记为“显式"吗? [英] Can you mark XUnit tests as Explicit?

查看:75
本文介绍了您可以将XUnit测试标记为“显式"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从NUnit过渡到XUnit(在C#中),并且我正在编写一些集成测试"(IT),我不一定希望测试运行器作为自动化构建过程的一部分运行.当由于环境因素(缺少数据等)而导致整个端到端流程可能无法正常工作时,我通常会手动进行测试.

I'm making the transition from NUnit to XUnit (in C#), and I was writing some "Integrated Tests" (ITs) that I don't necessarily want the test runner to run as part of my automated build process. I typically do this for manually testing, when the full end to end process might not work because of environmental factors (missing data, etc.)

在NUnit中,您可以使用显式属性标记测试,它只会被测试运行者跳过(除非您用特定的

In NUnit, you could mark a test with the Explicit attribute and it would just get skipped by the test runner (unless you marked the test with a specific Category attribute and told the test runner to target that category explicitly).

XUnit是否有类似的方法从测试运行程序中排除测试?

Does XUnit have a similar way to exclude tests from the test runner?

推荐答案

Jimmy Bogard用一个不错的RunnableInDebugOnlyAttribute解决了这个问题.请参阅此博客文章:在xUnit中明确运行测试.net

Jimmy Bogard solved this with a nice RunnableInDebugOnlyAttribute. See this blog post: Run tests explicitly in xUnit.net

public class RunnableInDebugOnlyAttribute : FactAttribute
{
    public RunnableInDebugOnlyAttribute()
    {
        if (!Debugger.IsAttached)
        {
            Skip = "Only running in interactive mode.";
        }
    }
}

这篇关于您可以将XUnit测试标记为“显式"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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