This is the last blog post I plan to make about the terminology around TDD. There will be real life examples from now on. I have previously discussed the terms collaborators, subject under test (SUT) and test doubles. Here, I am going to describe the three types of test doubles you can use. The Real Thing If you have a simple collaborator which only really stores and retrieves values, like a model, then is it worth replacing it for testing purposes? I personally think as long as this collaborator is unit tested then it is okay. Once there is someRead more
I have been posting about design patterns recently and I am realizing that it would be useful to post about Test Driven Development too. As a gentle introduction I am going to go through some of the vocabulary. Test Driven Development is the process; Red, Green, Refactor. That is the easy way to remember it. Below is your workflow: 1) Write a unit test. A unit test is a method that tests another method. The test calls the method that you are testing and verifies that the response is as expected. Your unit test should always use the same inputsRead more
Background Reading The creation method pattern The Problem? You want to use objects that are created else where and are of a set type but the implementations may vary. Examples? SocketManager, or any thing that needs to be replace during unit testing. How? The constructor of my complex object: public class CharacterFactory { public static var factory : NonPlayerCharacterFactory; public static function getAPlayer() : IPlayer { return factory.getAButton(); } } The using of the creation method: var player:IPlayer = CharacterFactory. getAPlayer(); Why is it good? • It is easy to understand; it is a simple pattern that needs little extraRead more
Background Reading The factory method pattern The Problem? You have a complex object, which has a lot of arguments in its constructor or you always want to construct the object using different sets of parameters. Examples? Socket Manager How? The constructor of my complex object: public function ComplicatedButton(colour:uint, mouseOverColour:uint, mouseOutColour:uint) { _mouseOverColour = mouseOverColour; _mouseOutColour = mouseOutColour; setUpGraphics(colour); addEventListeners(); } The using of the creation method: var redButton : ComplicatedButton = ComplicatedButton.getRedButton(); var blueButton : ComplicatedButton = ComplicatedButton.getBlueButton(); Why is it good? • It is easy to understand; it is a simple pattern that needs little extra code. It buildsRead more
Background Reading Read about the singleton The Problem? You want to have multiple instances of a singleton and want global access to them all. This may be because the objects use groups of resources, such as different groups of sounds, or because the objects need a lot of configuration, such as currency converters, or need global access, an event dispatcher. Examples? Currency converter, sound controller, global event dispatcher How? The Multiton: public class SocketManagerMultiton { private static var _instaces : Dictionary; public static const CHAT : String = “CHAT”; public static const WEATHER : String = “WEATHER”; public static functionRead more
Background Reading None The Problem? You want to ensure you have only a single instance of an object and want global access to it. This may be because the object uses a resource, such as sounds, or because the object needs a lot of configuration, such as a currency formatter, or needs global access, an event dispatcher. Examples? Currency formatter, sound controller, global event dispatcher How? The Singleton: package singletonpattern { /** * @author eamonn faherty */ public class SocketManagerSingleton { private static var _instace : SocketManagerSingleton; public static function getInstace() : SocketManagerSingleton { ensureInstanceExists(); return _instace; } private staticRead more