Skip to content

ClassDataSource - Is it possible to have two fixtures at different scopes on the same class? #991

Answered by thomhurst
richardoSGSI asked this question in Q&A

You must be logged in to vote

As part of the same instance (so injected at the same time)? Or two separate invocations, which would end up as different test cases?

For the former, no. For the latter, yes, and that's what the above would do.

If you did want the former, you could use property injection instead.

namespace MyTests
{
  public class MyTestClass
  {
    [ClassDataSource<MyFixture>(Shared = SharedType.Globally)]
    public required MyFixture Fixture1 { get; init; }
  
    [ClassDataSource<AnotherFixture>(Shared = SharedType.ForClass)]
    public required AnotherFixture Fixture2 { get; init; }
  }
}

Replies: 1 comment 2 replies

You must be logged in to vote
2 replies
@richardoSGSI

@thomhurst

Answer selected by richardoSGSI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants