We will not cover Unit Testing in this tutorial as it will be covered in separate posts but we will briefly describe why it is important to implement them and how to run them from the Unity Editor.
Uncomment the content of the ObjectivesInteractorTests class then select Window\Test Runner in the Unity Editor to display the above interface.
From here you can run all your unit tests and get results or see assertion failures.
Any method marked as [Test] will be displayed in the interface and can be ran.
Note: Any test suite intended to be ran must be placed in some Assets/
subfolder in a folder called Editor/ so it can be interpreted as tests by the Unity Editor and not be included in the build process.
It is important to test your business logic as it will provide you the following safeties :
– If you refactor some feature implementation from green (all corresponding tests are passing), then you can be sure that your new implementation is still correct if all tests keep passing (if all corresponding code paths have been covered by tests).
– Tests can help you to understand how a class in intended to be used from a client perspective.
– Tests help you to add new features without breaking things but it is your responsibility to maintain tests that cover edge cases of the newly added features.