Closed ChrisGora closed 4 years ago
I don't see any other way to be able to mock the Player class when I write tests
The World class is a very neat, pure C# class so there is no need to Mock it. But the Player class does all Unity stuff so it needs to be mocked
You're going to have to convince me tomorrow because personally do no agree with the way you've changed it.
Player is a class for storing internal state inside the world. I don't think anything outside of the world classes should be creating players.
Okay, I can see 2 solutions then:
1) The World has two methods CreatePlayer
and AddPlayer
. CreatePlayer
uses AddPlayer
. We say in comments that AddPlayer
is not meant to be used outside of the class (but has to stay public for testing).
2) The Player class methods become all package-private. This prevents anyone from doing anything with the Player other than instantiating it.
Neither are ideal but I need a way of mocking Players
TEST_ONLY_AddPlayer
then it's painfully obvious that it's for testing onlyNgl I think I agree with this. Pretty sure this is called Inversion of Control. Might be necessary anyway for adding other player types (if non-human players ever came up), since the world no longer cares about how to create a player, only that one exists.
This allows the Players to be mocked
kinda mean. we want to encourage plays to play the game regardless of their ability. this is the negativeness in the team i was talking about
This allows the Players to be mocked