Test assembly
\n[Collection<NoParallelCollection>]\npublic class MyTests \n{\n [Fact]\n public void TestType()\n {\n var tc = TestContext.Current.TestCollection;\n\n Assert.NotNull(tc);\n var xtc = Assert.IsType<IXunitTestCollection>(tc, false);\n Assert.Equal(typeof(NoParallelCollection), xtc.CollectionDefinition);\n }\n [Fact]\n public void TestParallel()\n {\n var tc = TestContext.Current.TestCollection;\n\n Assert.NotNull(tc);\n var xtc = Assert.IsType<IXunitTestCollection>(tc, false);\n Assert.True(xtc.DisableParallelization);\n }\n}
Yep, that comment was incorrect, so it's been deleted.
\nThe type-based attributes are not special; they just have names generated based on the type. The collection definition scanning process still looks through classes in the test assembly only.
\n\n\nAs the tests in the project do indeed get put into a collection (or at least a definition is \"found\")
\n
You can have collections without definition classes; those tests just get grouped into a definition to prevent cross-test parallelism. The only reason to have a definition class is to override the default behavior (like disabling cross-collection parallelism, as you're trying to do).
","upvoteCount":0,"url":"https://github.com/xunit/xunit/discussions/3326#discussioncomment-13525260"}}}-
I'm not sure if this is a bug or not, which is why I am starting a discussion. I have placed a Per @bradwilson 's comment in #1541 (comment) it sounds like this should now be a supported with xunit3:
The official documentation says the following and I'm not sure if it's outdated or not:
Obviously it seems to be partially working in-so-much that a test collection is being identified and applied to the tests, but the fact it drops the Here's an example. With the Shared assembly: [CollectionDefinition(DisableParallelization = true)]
public sealed class NoParallelCollection; Test assembly [Collection<NoParallelCollection>]
public class MyTests
{
[Fact]
public void TestType()
{
var tc = TestContext.Current.TestCollection;
Assert.NotNull(tc);
var xtc = Assert.IsType<IXunitTestCollection>(tc, false);
Assert.Equal(typeof(NoParallelCollection), xtc.CollectionDefinition);
}
[Fact]
public void TestParallel()
{
var tc = TestContext.Current.TestCollection;
Assert.NotNull(tc);
var xtc = Assert.IsType<IXunitTestCollection>(tc, false);
Assert.True(xtc.DisableParallelization);
}
} |
Beta Was this translation helpful? Give feedback.
-
Yes, this limitation is documented: |
Beta Was this translation helpful? Give feedback.
Yep, that comment was incorrect, so it's been deleted.
The type-based attributes are not special; they just have names generated based on the type. The collection definition scanning process still looks through classes in the test assembly only.
You can have collections without definition classes; those tests just get grouped into a definition to prevent cross-test parallelism. The only reason to have a definition class is to override the default behavior (like disabling cross-collection parallelism, as you're trying to do).