I have a bunch of tests that assume that my Tetris
class is composed by a Board
class. I now feel that instead of having a Board
inside of that Tetris
class, what I will want is to have a Board
inside a BoardEngine
class that is inside the Tetris
class. That is what this test is asking for:
[TestMethod]
public void Start_Game_And_Check_That_A_Red_Cube_Appears_And_Moves_Down_One_Pixel_On_First_Iteration() {
Board board = new Board(10, 22);
BoardEngine boardEngine = new BoardEngine(board);
Tetris tetris = new Tetris(boardEngine);
//test that the pixels are black/empty at first
Assert.AreNotEqual(Color.Red, tetris.GetColorAt(0, 0));
Assert.AreNotEqual(Color.Red, tetris.GetColorAt(1, 0));
tetris.Start();
//and that after running Start() the pixels are set to red
Assert.AreEqual(Color.Red, tetris.GetColorAt(0, 0));
Assert.AreEqual(Color.Red, tetris.GetColorAt(1, 0));
}
So to run this code I had to first create a BoardEngine
class. After that, I need an empty BoardEngine
constructor that accepts a Board
as argument. I then need to create an empty new constructor on Tetris
that accepts a BoardEngine
as argument.
If I try running the code, I will get a NullPointerException
. Why? Because when trying to do
tetris.GetColorAt(0, 0)
since in this constructor I am using now I haven't set the Board
in Tetris
to anything, it will just blow up.
My first question arises here. What to do now? In one hand, I can make this don't crash by setting that Board
to something. On the other hand, what I really want is not to set it to anything, what I'll want is to eventually get rid of it, so my Tetris
class only has a BoardEngine
attribute.
Am I supposed to go and refactor the tests themselves? I guess it's the only way of making this work. Am I missing something? At which time should I refactor the other tests? If I refactor them BEFORE trying to run this test, I then can mantain all those other tests green while this one is red. On the other hand, if I try to make this one be green asap, all the others are going turn to red :(
Here is an example of an old test:
[TestMethod]
public void ...() {
Board board = new Board(10, 22);
Tetris tetris = new Tetris(board);
tetris.Start();
Assert.AreEqual(Color.Red, board.GetColorAt(0, 0));
Assert.AreEqual(Color.Red, board.GetColorAt(1, 0));
}
Thanks