Recommended way to test ISerializationCallbackReceiver implementations?

I’ve got an implementation to ISerializationCallbackReceiver, and I wanted to test if my data was being saved properly. Is there a recommended way to do that?

The part I’m having a difficult time understanding is handling the serialization lifecycle in a test. Assuming my implementation is called MyClass, ideally, I’d like to

  • Create an asset that has MyClass attached to it.

  • Make some edits to its serialized fields.

  • Trigger a serialize of the SerializedObject.**

  • Trigger a deserialize.**

  • Get the instance of MyClass and validate the fields.

I’m not sure how to go about doing steps 3 and 4.

This is what I’m doing for now:

public void SetTypeShouldPersistAfterCallingSave(Type expected)
{
    var asset = ScriptableObject.CreateInstance<SerializableTypeHolder>();
    asset.Instance = new SerializableType(expected);
    AssetDatabase.CreateAsset(asset, AssetPath);
    asset = AssetDatabase.LoadAsset<SerializableTypeHolder>(AssetPath);
    var actual = asset.Instance.Type;
    Assert.AreEqual(expected, actual);
}

I think you can do asset = ScriptableObject.Instantiate(asset); to clone it and test your assertions, unless I’m missing something about it needing to use the filesystem.