Let's Write Unit Tests in Unity!
This article is a translated version of my original post on Qiita. Original (Japanese): https://qiita.com/segur/items/3dbddb29de537e978a1e
Apology
This article is an adaptation of an internal study session slide deck for Qiita. Please excuse any layout issues.
To Unity Developers
Let's Write Unit Tests Together!!
Ever Had This Experience?
You fix one bug, and suddenly, another part of your code that was working perfectly fine has a new bug!
Fixing Bugs Creates Bugs Elsewhere

Arrows indicate class references.
Should I consider B and C before fixing A?
Reality Is Even More Complex...
Various entities are intricately referencing each other.

It's impossible to consider every single entity's needs!
Create Unit Tests to Monitor Unintended Changes

Create unit tests to ensure class operation reliability!
Let's Write Unit Tests!
How to Write Unit Tests in Unity?
Without asmdef, You Can't Introduce Unit Tests in Unity

With asmdef, You Can Introduce Unit Tests in Unity!

Let's introduce asmdef!
What is asmdef (AssemblyDefinition)?
In Unity, you can define groups of C# files as assemblies.
Assemblies in Unity are similar to:
.so,.libin C.dllin .NET.jarin Java
Let's Introduce asmdef!
If the Reference Destination Isn't Supported, the Reference Source Can't Be Supported

If the Reference Destination Isn't Supported, the Reference Source Can't Be Supported

If the Reference Destination Isn't Supported, the Reference Source Can't Be Supported

Introduce asmdef starting from the endpoints!
Gradually Introduce asmdef from the Endpoints!
Reality Is Even More Complex...

Where are the endpoints?
Align the Direction of References!

Though it requires tedious work, align the direction of references!
How Do We Align Reference Directions?
Though it's challenging, it can be done using various methods!
- Dependency Inversion Principle
- Dependency Injection
Please google for more details.
Is It Really Worth the Effort?
It Is Worth It!
Without vs. With Unit Tests
