Skip to content

System.NotSupportedException when using AsyncEnumerable test cases for TestCaseSourceAttribute #4802

@vjred

Description

@vjred

Example test case

  public static async IAsyncEnumerable<TestCaseData> AsyncEnumerableTestCases()
  {
      await Task.Delay(100); // Simulate an asynchronous operation
      yield return new TestCaseData(42, 42);
      await Task.Delay(100); // Simulate another asynchronous operation
      yield return new TestCaseData(51, 51);
  }
  
  [TestCaseSource(nameof(AsyncEnumerableTestCases))]
  public async Task TestAsyncEnumerable(int expected, int actual)
  {
      await Task.Delay(100); // Simulate an asynchronous operation
      actual.Should().Be(expected);
  }

Error

System.NotSupportedException : Specified method is not supported.
.AsyncEnumerableTestCases()+System.IAsyncDisposable.DisposeAsync()
   at NUnit.Framework.Internal.AsyncEnumerableAdapter.AsyncEnumeratorWrapper.<Dispose>b__4_0()
   at NUnit.Framework.Internal.AsyncToSyncAdapter.Await[TResult](Func`1 invoke)
   at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
   at NUnit.Framework.Internal.AsyncEnumerableAdapter.AsyncEnumeratorWrapper.Dispose()
   at NUnit.Framework.TestCaseSourceAttribute.GetTestCasesFor(IMethodInfo method)

Notes:

  1. On debugging, its failing on this line.
  2. This snippet used to work before nUnit 4.2.0 , and looks like the feature added in AsyncEnumerable support for TestCaseSource, ValueSource, and TestFixtureSource #4538 regressed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions