Unittests for exercise 43


#1

Hello,
I’m trying to write some unittests for a stripped down version of ex43.py and I’m not sure how to write a test for the Engine Class. Any ideas?
What do I need to test on it?


#2

Hmmmm, that’ll be tough without doing a mock, so check out this:

https://docs.python.org/3/library/unittest.mock.html

Basically, you’d create either a mock Map or a Map that has a bunch of mock rooms. Have them return the name of some fake room or just whatever you need to make the test go. Then you run the Engine with that.

The other option is create a couple test rooms in your test. Then put those in the Map. Then pass that to the Engine. Your fake test room can just return something simple.