2017-02-21 80 views
0

我有一个c#visual studio项目,我在其中使用xunit进行测试。Xunit TestNames总是包含命名空间

现在的测试资源管理器显示了他们的命名空间的测试是这样的:

enter image description here

我不想在测试名冗余杂乱。

我知道我可以注释方法来设置testnames这样的:

public class WhenCreating : GivenConnection 
    { 
     [Fact(DisplayName = nameof(GivenConnection) + "." + nameof(WhenCreating) + "." + nameof(ItAppliesFromCity))] 
     public void ItAppliesFromCity() 

但这仍然是非常多余的,因为我会标注具有相同前缀的每个方法。有什么方法可以影响测试名称生成?像ParentClass.SubClass.Method

更新: 要写得更有表现力:我仍然想在测试名称中使用父类的名称。不仅可以通过app.config完成的方法名称

+1

请参阅http://stackoverflow.com/questions/32351210/how-can-xunit-be-configured-to-show-just-the-method-name-in-the-visual-工作室-20题目来完成你的目标。 – Pasick

+0

我不认为这是重复的,因为它不会将父类添加到测试名称。在上面的示例中(GivenConnection) –

回答

1

在您的App.config文件中设置xunit.methodDisplay。

<configuration> 
    <appSettings> 
    <add key="xunit.methodDisplay" value="method"/> 
    </appSettings> 
</configuration> 
+0

这不会将父类添加到方法名称 –

+0

要显示父类名称,请将此属性设置为“classAndMethod”值 – Pasick

相关问题