[SOLVED] Unit Test of Editor code

Hello everyone,
I have a simple editor tool that create assets from the content of a CSV. I use the UnityEditor namespace to access the [MenuItem()] and the AssetDatabase, so the script is placed in the “Editor” folder.

I want to test this code with the Test Runner, but I can’t instantiate my class to test it; it does “not exist in the current context”.
I tried moving the EditMode Test Assembly Folder in the Editor folder, and used UnityEditor in the test as well, but that didn’t resolved the error, and I really can’t find any information about this online.
From what I understand from this post , it might be related to the script compilation order, but I don’t know how to do something about it when it comes to test specifically.

Have you implemented test for Editor tools like that? Is it even possible? Please tell me if I misunderstood something, I’m still new to unit test and Unity.

Take care,
Nighten

It’s certainly possible to test Editor code, yes (we do so extensively).

Putting the code in a folder named ‘Editor’ is not enough; you need to use an Assembly Definition File for your Editor code (set to include the ‘Editor’ platform only).

Then you need to configure the Assembly Definition File for your tests folder to 1) include the Editor platform only and 2) reference the Assembly Definition File for your Editor code.

Thank you so much for those instruction! I really missed those steps, but now it’s working properly.

1 Like