50 Shades of Green
The 21st century is in the yard, which means testing is one of the essential parts of development not only in game development but also in any software product.
In large companies, testing handled by QA (Quality assurance) department and is an essential part of the development process. Of course, in small teams, anyone can do this (typically a game designer or a programmer), in the end, games come out with bad quality, and testing happens on players =)
The technical side of quality control is also a pretty big topic. To help developers test games on the device, Unity has the Unity Remote tool. For testing at a more global level, there are Test Flight for Apple devices and closed channels on Google Play for Android. Also, there are many smaller features, like tools for logging https traffic to check specific network requests.
This article will be about creating unit tests, a small part of a vast topic that should make a programmer’s life easier.
Programmers have a bunch of tools and practices. An extraordinary surge of interest in testing noted in the early 2000s when the concepts of Extreme Programming and Test-driven development formed. Unit testing is one of the fundamental tools of these practices. Finding information on this topic on the Internet is quite easy, so we will not focus on the explanation of the basics. If you need more details about fundamentals, start with Wikipedia, especially pay attention to advantage and disadvantage paragraphs, and feel free to return here for practical examples for Unity.
Unity Test Framework is the primary tool to create unit tests in Unity. It based on NUnit, and since this is the most popular testing framework for C#, familiarizing yourself with its documentation will be useful.
Open Test Runner
Window > General > Test Runner
PlayMode and push
"Create PlayMode Test Assembly Folder" for our tests
"Create Test Script in current folder" to create new script
For code in need of testing, create
Create > Assembly Definition
Add link to our
Assembly Definition into
Tests.asmdef file, wihch located in Tests folder
Don’t forget to push the
"Apply" button at the bottom and safe changes
In the script created in step 3, we write our tests
Rejoice with the result
Those steps are a small example to demonstrate the creation of a unit test in Unity (Full testing code can be fount at Hints Library). For the proper testing of functionality, a large amount of time and code should be sacrificed to the testing altar. Often the test code turns out to be even larger than the business part code, but this will help save even more time for catching errors related to regression. It’s clear that unit tests are just a small part of all the necessary testing, you still need to add integration tests, as well as test the UI, but this is beyond the scope of the article about unit tests. See you next time! =)