sentry-unity icon indicating copy to clipboard operation
sentry-unity copied to clipboard

SentryInitialization.Init is always called in tests

Open semuserable opened this issue 3 years ago • 4 comments

SentryInitialization.Init is called even for the simplest test because of RuntimeInitializeOnLoadMethod attribute.

public void AssertPass()
  => Assert.Pass();

I encountered some not expected side effects while I was writing tests for UnityEventProcessor.

semuserable avatar Jul 05 '21 06:07 semuserable

Not sure how we can skip it just for tests. Doesn't look like there's compilation directive set when compiling for tests which makes sense since you might just run tests on a normal build.

bruno-garcia avatar Mar 15 '22 15:03 bruno-garcia

We could disable the SDK selectively for those tests where we Initialize the SDK as part of the test by loading and disabling the ScriptableOptions within the editor?

bitsandfoxes avatar Mar 17 '22 18:03 bitsandfoxes

Hmm, why is it [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]? Looks like something called multiple times even during normal runtime (regardless of tests)? Maybe we should instead use another event, for example this one sounds about right: AfterAssembliesLoaded

vaind avatar Apr 12 '22 08:04 vaind

I think think this was due to AfterAssembliesLoaded and BeforeSplashScreen not being called in the Editor. But since the Initialization now compiles with the game and we now have access to precompile directives we should rethink this.

bitsandfoxes avatar Apr 12 '22 13:04 bitsandfoxes

Disabling self-initialization during tests with this If individual test classes are supposed to be executed with self-initialization disabled they should inherit from this.

bitsandfoxes avatar Dec 12 '22 11:12 bitsandfoxes