dmulligan wrote:
When trying to write a unit test for my game I ran into a bit of a problem. I am looking for the best way to replace one or more of the system classes with mock objects. As far as I can see the only way I can do this with Artemis is to extract the code I wish to replace into a delegate and let the system class choose between the test and production versions.
It would be nice if I could choose the key that the system manager uses to map my systems with, that way I can swap out any system class without having to let other classes that refer to it know about the change. However this breaks the GoF recommendation to favour delegation over inheritance so perhaps it would be best to keep it the way it is.
How many Artemis users are unit testing? Also what has been your approach to this problem?
I had the same problem just a few days ago, I tried to have systems that could replace each other.
I solved it by having each type of system implement an interface, then fetching systems taking the interface class as argument, then looking in the system manager for a class implementing that interface.
More about this in
this blog post (including my fetch code).
I hope this helps!