I’m a rapper
Ok, not really. But I did a lot of wrapping today. Before I did that though, in the morning I paired with Mateau, one of the craftsmen at work, and tried to navigate a lot of code that I wasn’t familiar with. He gave me good advice and told me to focus on the little part we are trying to solve and then go from there. Otherwise it can be overwhelming navigating a large code base.
This is the approach I tend to have when learning during my apprenticeship. It makes sense when there’s a lot in front of you to focus on the small part you can tackle first, which will lead you to the next part and you can deal with that when you get there.
It is similar to Christoph, another craftman’s talk, “Focus on the sprint not the marathon”. It’s also similar to this quote by Arthur Ashe, “Start where you are, use what you have, do what you can.” Definitely something I always try to do, one problem at a time.
In the afternoon Georgina, another apprentice helped me think about how to test my Echo Server. Here is some of what I learnt:
- Wrap the creation of new objects that you want to test the behaviour of in an interface.
- Spotting object creation is a good place to start when you want to know where to create an interface.
- Use an implementation of the interface you want to fake in your tests so you can try out different behaviour.
- You can use another implementation of the interface and swap that one into your real program when you want the actual program to execute with the real object.
- You can spy on certain behaviour by having methods within your implementations that can check if certain methods have been called or check what the state of the object is (changing a Boolean from false to true if a socket has been closed for example).
- You can even wrap wrappers if the return value of the original object is not what you want to test.
- Wrapping wrappers gets confusing, but diagrams help.
- Wrapping is a great way to test the behaviour of things you do not have control over during the real execution of a program, because you can simulate the behaviour you want.
9. I have a lot of wrapping to do.
How to test my Echo Server now makes a lot more sense! Maybe I shouldn’t get too carried away with wrapping though… I know there are some trade offs I’m making in the process.