테스트 용으로 ValueSourceAttribute
을 사용하려고합니다.ValueSourceAttribute에 지정된 sourceName이 null이 아닌 정적 필드, 속성 또는 메서드를 참조해야합니다.
여기 그러나 그것이 같은 방식으로 정의 된 경우에도, 두 번째 인수를 해결할 수없는, 예를 들어
[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