-
Notifications
You must be signed in to change notification settings - Fork 2
3. Assembly Definitions in Unity and Running Tests
Shahid Karim edited this page May 12, 2020
·
2 revisions
- Once you've followed all the steps below, try to generate a build manually.
- If you get any errors:
- You MUST add an asmdef file to EVERY Editor folder that is showing an error in the Console.
- In the asmdef file uncheck
Any platform
then make sure onlyEditor
is selected. - Keep trying to generate a build and doing the above until the build generates successfully.
- Right click on the Assets folder > Create > Assembly Definition. This will create an asmdef file in the Assets folder.
- Select the asmdef file, name it External, then make sure Auto Referenced and Override References are selected.
- Add Assembly Definition References as required (You can tell an assembly definition reference is required from reading the console)
- Add Assembly References as required. (You can tell an assembly reference is required when you have third party DLLs that need to be included into your game.
- Right click on your Scripts folder > Create > Assembly Definition. This will create an asmdef file in the Scripts folder.
- Select the asmdef file, name it Internal, then make sure Auto Referenced and Override References are selected.
- Add the same references as the one from the External asmdef file. Include the External asmdef file you created as well.
- Add the same Assembly References as the External asmdef file.
- Right click on the Assets folder > Create > Testing > Tests Assembly Folder. This will create a folder for your test scripts.
- Select the asmdef file, name it Tests, then make sure Auto Referenced and Override References are selected.
- Add only External and Internal to the Assembly Definition References.
- Add nunit.framework.dll if it wasn't already included in the Assembly References.
- In the Tests folder that was created from the steps above, right click > Create > Testing > C# Test Script.
- Open the new Test script after renaming it to whatever test you want to do.
- Add
[Test]
above the methods that are methods you want to run as tests. - Make assertions within the methods marked with
[Test]
- In Unity, Click on Window > General > Test Runner and dock it to the screen.
- Once the previous steps have been followed, the methods that were marked as Test will now display on the Test Runner window.
- To run the tests click Run All or double click on the test you want to run.