0
我试图使用ValueSourceAttribute
进行测试。在ValueSourceAttribute上指定的sourceName必须引用非空静态字段,属性或方法
下面是一个例子
[Test]
public async Task TestDocumentsDifferentFormats(
[ValueSource(nameof(Formats))] string format,
[ValueSource(nameof(Documents))] IDocument document)
{
有趣的是,Formats
名单(第一个参数)的作品完美,但它解决不了第二个参数,即使以同样的方式定义。
这是我如何定义文档静态列表
public class DocumentFactory
{
public static readonly List<IDocument> Documents=
new List<IDocument>
{
// Init documents
};
}
但是当我尝试运行我的测试中,它抛出一个错误。
The sourceName specified on a ValueSourceAttribute must refer to a non null static field, property or method.
什么会导致此问题?我会很感激任何帮助。
您应该提到只有在另一个类中声明'Documents'属性时才会出现此问题。 – Fabio
@Fabio是的,它是在另一个类中声明的,是否有可能解决这个问题? – bxfvgekd