The answer to your Y (as in the classic X=>Y question) is that you use protected $extraDataobjects = [ThatClass::class,..., etc.];

Calling onBeforeWrite() directly got it to pass without complaints

However sometimes it's not plausible, due to varying constraints.

calling directly would be the correct way to unit test that, yes @webbower

Should I just call ->onBeforeWrite() manually and then do the assertion?

How do you test the behavior of MyDataExtesion::onBeforeWrite()? I have a test class class TestDataObject extends DataObject implements TestOnly, but when I call ->write() on the instance in my test code, it fails because there’s no DB table for the test object (edited)

oh okay. that's is what i'm looking for for my web project, how can i create similar as that?