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