xUnit to TUnit - How to implement multiple fixtures in a single CollectionDefinition? #926
-
|
Hi all, I'm trying to convert a class like this: using Tests.Common.Fixtures;
using Xunit;
namespace MyTests.Tests
{
[CollectionDefinition("MyTests.Tests fixture collection")]
public class FixtureCollection : ICollectionFixture<MyFixture1>, ICollectionFixture<MyFixture2>, ICollectionFixture<MyFixture3>
{
// This class has no code, and is never created. Its purpose is simply
// to be the place to apply [CollectionDefinition] and all the
// ICollectionFixture<> interfaces.
}
}and then use it like: namespace MyTests.Tests
{
[Collection("MyTests.Tests fixture collection")]
public class Tests
{
public Tests (MyFixture1 myFixture1, MyFixture2 myFixture2, MyFixture3 myFixture3)
{
...
}
}
}I saw that it's possible to do a single fixture via this thread: [ClassDataSource<MyFixture>(Shared = SharedType.Globally)]I also saw there were things like DataSourceGeneratorAttribute and ClassConstructorAttribute, but I'm not sure what would be appropriate Any ideas? Thanks! EDIT: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Hey @richardoSGSI - I've just pushed v0.1.1063 which can support injecting up to 5 generic arguments via ClassDataSource. So you could do: Regarding using the So it's possible, but you'd have to implement it yourself. You can look at the source for |
Beta Was this translation helpful? Give feedback.
-
|
Just as a follow up, did injecting multiple fixtures via |
Beta Was this translation helpful? Give feedback.
Hey @richardoSGSI - I've just pushed v0.1.1063 which can support injecting up to 5 generic arguments via ClassDataSource.
So you could do:
Regarding using the
DataSourceGeneratorAttribute- You'd have to implement it yourself.ClassDataSourceis actually built on top ofDataSourceGeneratorAttribute- And simply uses the Shared argument to store already created instances in dictionaries etc.So it's possible, but you'd have to implement it yours…