当我尝试运行我的xUnit.net测试时,我会得到以下错误:
[xUnit.net 00:00:00.63] xunit.UnitTest1.TestTheAnswer [FAIL]
Failed xunit.UnitTest1.TestTheAnswer [1 ms]
Error Message:
System.NotSupportedException : Specified method is not supported.是什么导致了这个错误?
发布于 2022-10-04 16:14:05
TL;DR:public
因此,造成此错误的另一个原因是属性/字段/方法必须是public,这可能并不明显。
弹出帮助只提到成员必须是static,并且返回值必须与IEnumerable<object[]>兼容。它没有提到访问修饰符。正如问题中所述,运行时的错误消息在这方面也没有帮助。
(我使用的是xunit 2.4.1版本,试图使用private属性,但失败了。)通过使属性public解决。)
发布于 2022-06-02 09:55:41
在我的例子中,我在定义测试数据时缺少了静态关键字:
public static IEnumerable<object[]> AdminDevicesFetchActionTestData() {...}
[Theory]
[MemberData(nameof(AdminDevicesFetchActionTestData))]
public async Task HandleAsync_AdminDevicesFetchAction_ShouldReturnValidResponse(AdminDevicesFetchAction action,
AdminDevicesResponse expectedResponse)
{发布于 2022-11-26 05:32:30
以防其他人面临这个问题。在我的例子中,我有一个公共静态方法,如下所示。
public static IEnumerable<object[]> MyTestDataSet(string name, short testData)
{
yield return new object[]
{
TestDataBuilder.BuildTestConfiguration(name),
TestDataBuilder.GetEntityWithTestData(testData),
};
}
internal static TestEntity GetEntityWithTestData(short param)
{
//returns entity by assigning param to one of its properties defined as short.
}对我不起作用的:
[MemberData(nameof(MyTestDataSet), "TestName", 800)]最后对我有用的是:
[MemberData(nameof(MyTestDataSet), "TestName", (short)800)]似乎静态方法param类型必须准确地定义它(在本例中是简短的),并且没有默认的转换。
此外,我希望这可能会对将来面对这个问题的人有所帮助。
https://stackoverflow.com/questions/70992289
复制相似问题