3 ms·
One benefit of testing is that it can highlight whether your abstractions make sense. If you need to pull in the world to test a small module then probably your
by halayli 10y ago
One benefit of testing is that it can highlight whether your abstractions make sense. If you need to pull in the world to test a small module then probably your dependencies are not right and what you thought was a unit turns out to be more than that.
When I am writing a module/function, I tend to continuously think of how this can be tested, which helps me design better abstractions.
For example if you're writing a class that uses a socket read/write, when testing you probably need to mock them. If you weren't planning on writing tests then probably you'd have ended by having the methods embedded in the class itself as read/write/close when those methods don't belong to the class and should be in another module called Socket that inherits a Socket interface. Now that you have a socket interface it becomes easier to test your class by passing a mock Socket interface.