2

I'm trying to add unit tests to a Unity project. I'm using the Unity TestRunner window, adding an Edit Mode Test Assembly Folder, and adding a test C# script to it. The file is generated fine.

However, I can't actually test any of the main project's code because the test project can't see it. The Tests.csproj that Unity is setting up doesn't include any of the .cs files from the main directory tree; all it includes is, for some reason, a .txt file. I can change this situation temporarily by copying over the XML from the main project's .csproj file into Tests.csproj, but Unity rewrites Tests.csproj to put it back how it had it the next time it pays attention.

The Unity documentation doesn't hint at anything like this needing to be addressed. The MSVS documentation says I need to add a Reference to the project, but the Tests > References context menu under Unity doesn't have the Add Reference option it talks about.

What am I doing wrong?

1 Answer 1

4

I believe you have to follow the assembly definition paradigm they rolled out recently.

Example:

  • in Assets, create a Graphics folder
  • add some classes to it
  • add an Assembly Definition

  • in Assets, create a TestsEditMode folder using Test Runner window

  • add some tests to it still with Test Runner window
  • add an Assembly Definition then reference Graphics in it

You end up with the following:

enter image description here

The documentation is confusing, as usual ...

Basically this turns out to be opt-in, which is rather good in the end.

Not the answer you're looking for? Browse other questions tagged or ask your own question.