Skip to content
\n

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}
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Yep, that comment was incorrect, so it's been deleted.

\n

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.

\n
\n

As the tests in the project do indeed get put into a collection (or at least a definition is \"found\")

\n
\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"}}}

Xunit3 - Type-based CollectionDefinition in shared Assembly #3326

Discussion options

You must be logged in to vote

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.

As the tests in the project do indeed get put into a collection (or at least a definition is "found")

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).

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@pinkfloydx33
Comment options

@bradwilson
Comment options

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