Day 15 – Writing Tests
Nothing to show today as I spent my time refactoring the turn management code and writing tests for it.
I’m a big fan of automated testing and writing unit tests, but so far have not done it in Unity. It’s always best to start with it early on so even though this is still a prototype with a lot of trial-and-error, I forced myself to cleanup the code and figure out how best to test it.
Most of the Unity specific classes don’t lend themselves very well to unit testing using things like mocks. You can test them but they run inside a Unity scene, require a bit more setup and most importantly: take more time to execute.
I really want to have tests for my core state management code, so I spent most of the time removing dependencies to Unity classes in order to execute the tests much faster with the standard NUnit runtime.
Took a bit of time but goal achieved: I think my code is cleaner, better documented, more tested and everything still works as before.
Now I just have to work on the habit of keeping it up…
PS: If you want to know more about habits in general, I can recommend Atomic Habits. Easy to read and insightful book, lots of good tips.
Leave a Reply