Table of Contents
  v2 v3 AOT   Error

xUnit3006

"Test case implementation must be serializable"

Cause

A violation of this rule occurs when a test case implementation is known to not be serializable.

Reason for rule

Test cases in v3 reflection-mode must be serializable, because their serializable contents are provided to VSTest so that they can later be run individually from Test Explorer.

How to fix violations

To fix a violation of this rule, either implement IXunitSerializable on the test case, or support its serialization with a third party class that implements IXunitSerializer.

Examples

Violates

using Xunit.v3;

public sealed class xUnit3006 : IXunitTestCase
{
    // ... implementation of IXunitTestCase ...
}

Does not violate

using Xunit.Sdk;
using Xunit.v3;

public sealed class xUnit3006 : IXunitTestCase, IXunitSerializable
{
    // ... implementation of IXunitTestCase ...

    // ... implementation of IXunitSerializable ...
}
using Xunit.Sdk;
using Xunit.v3;

[assembly: RegisterXunitSerializer(typeof(xUnit3006Serializer), typeof(xUnit3006)]

public sealed class xUnit3006 : IXunitTestCase
{
    // ... implementation of IXunitTestCase ...
}

public class xUnit3006Serializer : IXunitSerializer
{
    // ... implementation of IXunitSerializer ...
}