I am currently writing a little Python adaptation of Rummy 500 to (re)familiarize myself with the language and unittest.
I have most of my application written and running, and now it is time to test the actual game flow.
I believe my final unittest will actually simulate a given game from start to finish and confirm that the state matches what is expected during / after the game resolves.
My plan is to use mock to pass a long series of inputs to the game in order to non-interactively test that the game works interactively. I believe I can just do something like the answer suggested here: Mock user input() but with a very long array for lines like
@mock.patch('builtins.input', side_effect=['11', '13', 'Bob'])
I am sure that this will work, but I can see it becoming an unwieldy mess as the input list gets longer.
Is there a better way to accomplish this same goal? My naive thought is to have a series of unit test suites that build on each other so I can just add to an array of inputs as I test each stage of the game, one after another.
E.g.
inputs_first_turn = ['Player 1', 'F', 1, 2, 1, 5, 'Player 2', 'M', 1, 3, 2, 5]
@mock.patch('builtins.input', side_effect=inputs_first_turn)
def test_first_turn(self, input):
game = Game()
# tests on game state go here
inputs_second_turn = inputs_first_turn + [3, 1, 2, 2, 5, 3, 3, 2, 4, 5]
@mock.patch('builtins.input', side_effect=inputs_second_turn)
def test_second_turn(self, input):
game = Game()
#tests on game state go here
repeat ad nauseum until I finish the game.
I believe this would work and would be both readable (as can be, at least) and maintainable, but I want to think there's an easier way. I am not concerned with the flow within the tests, I can muddle through that myself, but if there is a better way to do this, I would love to know.