Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xUnit v2 CollectionDefinitionAttribute FS0842: This attribute is not valid for use on this language element #18373

Open
KarenTazayan opened this issue Mar 11, 2025 · 2 comments
Milestone

Comments

@KarenTazayan
Copy link

As I see from the documentation, F# 9 introduces a new feature called 'Enforce attribute targets.' It breaks all my tests with xUnit v2, which were written in F# 8, when I try to update my projects to .NET 9 and F# 9.

type TestSiloConfigurator() =
    interface ISiloConfigurator with 
        member this.Configure(siloBuilder: ISiloBuilder) =
                siloBuilder.AddMemoryGrainStorage(PersistentStorageConfig.AzureSqlName) |> ignore
                siloBuilder.AddMemoryGrainStorage(PersistentStorageConfig.AzureStorageName) |> ignore

type ClusterFixture() =
    let mutable cluster = null

    do
        let builder = new TestClusterBuilder()
        builder.AddSiloBuilderConfigurator<TestSiloConfigurator>() |> ignore
        cluster <- builder.Build()
        cluster.Deploy()

    member this.Cluster with get() = cluster
    interface IDisposable with member this.Dispose() = cluster.Dispose()

type Starter(messageSink: IMessageSink) =
    inherit XunitTestFramework(messageSink)

[<CollectionDefinition(CurrentAssembly.ClusterFixture)>]
type ClusterCollection = 
    inherit ICollectionFixture<ClusterFixture>

[<assembly: Xunit.TestFramework(CurrentAssembly.TypeName, CurrentAssembly.Name)>]
()

What can I do in this situation?

@majocha
Copy link
Contributor

majocha commented Mar 11, 2025

Yeah xUnit have some annoyances. Collection definition should be just an emppty class.
Try this:

[<CollectionDefinition(CurrentAssembly.ClusterFixture)>]
type ClusterCollection() = 
    interface ICollectionFixture<ClusterFixture>

@KarenTazayan
Copy link
Author

@majocha Thank you! Now I use it as a class, and it seems that the code below works

[<CollectionDefinition(CurrentAssembly.ClusterFixture)>]
type ClusterCollection() = 
    interface ICollectionFixture<ClusterFixture> with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

No branches or pull requests

2 participants