Skip to content

Conversation

@bash
Copy link
Member

@bash bash commented Jan 30, 2025

xUnit v3 has introduced a new way to support serialization of objects via an external IXunitSerializer (instead of implementing an interface on the object itself).
See: https://xunit.net/docs/getting-started/v3/custom-serialization

Implementing a serializer means that a type can be used in theory data (I think xUnit v3 is a lot more strict about this, not even showing the individual rows anymore if a type is not serializable).

This PR adds serializers for Option<T>, Either<L, R> and Unit.
There is no serializer for Result<T> since Exceptions are not xUnit-serialisable.
I also left out EitherOrBoth<L, R> for now (rarely used).

The serializers are discovered via assembly-level attributes implementing IRegisterXunitSerializerAttribute. Funcky.Xunit.v3.targets automatically adds these attributes to projects depending on Funcky.Xunit.v3 for a frictionless out-of-the-box experience :)

I also had to introduce two marker interfaces: IOption and IEither as IRegisterXunitSerializerAttribute does not support open generics (e.g. typeof(Option<>)).

Open Questions:

  • Instead of having three attributes (one for each serializer). We could have one attribute that supports all types and a "meta"-serializer that calls the other serializers. Advantage: smaller API surface.

@bash bash force-pushed the xunit-v3-serializers branch from a57099b to ae0ef48 Compare January 31, 2025 13:52
@bash bash force-pushed the xunit-v3-serializers branch from ae0ef48 to 1ad6766 Compare January 31, 2025 14:04
@bash bash marked this pull request as ready for review January 31, 2025 14:05
@bash bash requested review from FreeApophis and Mafii January 31, 2025 14:05
@bash bash enabled auto-merge January 31, 2025 14:05
Copy link
Member

@Mafii Mafii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure what upsides this adds, maybe you need to explain it to me.

curretly I don't think I want to accept it, as the interfaces add noise to the types...

@bash
Copy link
Member Author

bash commented Feb 2, 2025

I'm not 100% sure what upsides this adds, maybe you need to explain it to me.

I feel like I explain the motivation fairly well in the PR description:

Implementing a serializer means that a type can be used in theory data (I think xUnit v3 is a lot more strict about this, not even showing the individual rows anymore if a type is not serializable).

@bash bash merged commit 1b5140a into main Feb 4, 2025
9 checks passed
@bash bash deleted the xunit-v3-serializers branch February 4, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants