Using TDD and MVP Design Pattern

Hey!

Sorry for the delay here. I had an issue on release with my game and then… well, new WoW expansion :wink:

I’ve created an example, you can find it here::

You should be able to build and run this, as well as run the tests, but if you have trouble maybe build the main project first (without the test project), then build the whole solution. Also, note that the test project uses NuGet to get both MonoGame and NSubstitute, so you’ll need to have an internet connection on whatever computer you build with.

The sample contains two implementations of moving a ball around the screen, stopping it when space bar is held. The first, MainGame, just implements it directly and doesn’t make any considerations for MVC or testable code. The second, MainGame_Part2, uses an MVC implementation following SOLID principles (more or less) and provides tests for objects that don’t interact with MonoGame objects directly.

If there’s interest, I’ll create a second part of this example that wraps up the MonoGame objects and allows for all the code to be tested :slight_smile:

Finally, my original plan here was to use this example in a tutorial video that I was going to upload to my YouTube channel. After about an hour of recording, at which point I was only just finishing the GameEngine class and tests, I realized that this was going to be too much. I highly doubt you (or anyone) wants to watch three hours of tutorial on this. Instead, I’ll just provide the example code as-is. I did go through and write comments at the top of all the files to explain things and to point out various concepts. Hopefully you still find this useful. Much respect to those people who manage to make coding tutorial videos and keep them in the 10-20 minute range :wink:

Anyway, when going through the code, start at Program.cs. The comments should guide you through the rest. I hope it helps, and if you have any questions, feel free to post them here and I’ll try to help you out.

Good luck!