visual-studio-2013 - 测试命名 - Resharper 和 xUnit

标签 visual-studio-2013 resharper bdd xunit

在 R# 8.2.0 和 VS2013.3 中,我想按 Traits 对测试运行器进行分组,就像在 VS 测试运行器中一样:

问题:我能否让 R# 显示这样的测试:

enter image description here

在 R# 中,我能得到的最接近的是:

enter image description here

测试代码为:

    [Trait("Homepage", "User changes sort order to highest rating first")]
public class ChangeSortOrderToRating : IntegrationTestBaseWithData {
    readonly JokeViewer viewer;
    public ChangeSortOrderToRating() {
        viewer = new JokeViewer(new Session());
    }

    [Fact(DisplayName = "Show all 3 Stories")]
    public void ShowAllStories() {
        List<Joke> result = viewer.ShowAllJokesHighestRatingFirst();
        Assert.Equal(3, result.Count);
    }
    [Fact(DisplayName = "Show all Stories in rating order")]
    public void ShowListOfStoriesInDescendingRankOrder() {
        var result = viewer.ShowAllJokesHighestRatingFirst();
        // 10,2,5 is order of insert in db
        // First should be rating of 2
        Assert.Equal(10, result[0].Rating);
        Assert.Equal(5, result[1].Rating);
        Assert.Equal(2, result[2].Rating);
    }
}

已安装 xUnit 的 R# 扩展: enter image description here

最佳答案

如果你的意思是你想避免其中的方法名称,不幸的是,现在,这实际上是不可能的。

ReSharper 插件与 xunit 1.x 一起工作的方式意味着在测试实际运行之前显示名称不可用(因为插件使用 xunit 的 API 来定位测试,但是 DisplayName 无法调用属性,因为它查看的是源代码而不是编译后的代码。DisplayName 可能正在对代码执行任何操作(例如,Theory 属性添加参数信息),因此在从代码构建测试时没有可使用的值。

我希望 xunit 2.x 的支持能够解决这个问题。 2.x 非常努力地确保可以根据源代码分析检索所有信息,因此 xunit API 可以调用类似反射的抽象来获取所有信息,包括一个漂亮的显示名称。对 2.x 的支持目前正在进行中,测试运行良好,但仍在使用 xunit 1.x 来发现测试。

关于visual-studio-2013 - 测试命名 - Resharper 和 xUnit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26042016/

相关文章:

c++ - `std::vector` 迭代器生成巨大的汇编代码

visual-studio - 如何在调试时不按 fn 键使用功能键

visual-studio-2012 - 将 VS2013 SSIS 包部署到 SQL Server 2012 并在 VS2012 中编辑

visual-studio - Resharper 导航到通用接口(interface)的具体实现?

c# - 在 VS2008 中用花括号 {} 包围代码块的任何方法?

c - 测试运行 null 和字母?

c# - VS2017 显示错误 : Dictionary is not a collection

javascript - 使用 jasmine-node 测试节点命令行应用程序

dns - Behat + Mink 无法使用代理(DNS 无法解析域名)

testing - BDD 可以完成 "after"吗?