Attribute for a test only public method.

Hello,

I’m currently writing unit tests for my classes and there are multiple classes that need a specific setup so we can see the widget on screen. Those are UI tests so the canvases and the settings for the tests are quite different than in game, but I just want to make sure that the visuals are updated correctly and that the tests don’t crash. Anyways, what I did so far is create a method InitForTests and put this method inside a #if UNITY_EDITOR #endif block. The problem here is that this code executes in play mode of course and not in standalone (good behaviour).

I was wondering if there was an attribute I could put on my method so it only compiles or is only used for when running tests to avoid other programmers of calling this method by mistake.

Thanks!

If it’s called InitForTests, is it really plausible that someone would call it by mistake?

You could use the [EditorBrowsable] attribute to hide the method from autocomplete, maybe.