3 ms·
Not sure this would be great for new code, because the tests are supposed to dictate the function’s behaviour, and not the other way around. Yet, this would be
by jiehong 4y ago
Not sure this would be great for new code, because the tests are supposed to dictate the function’s behaviour, and not the other way around.
Yet, this would be amazing for legacy projects with no unit tests: you could record the code in production, and generate unit tests from there, and add them to the non-tested project.
It would bring you a safety net allowing you to better work on that legacy project IMO.
This actually reminds me a an attempt at an internal tool I saw pass by whose goal was to save all IO for a given request (aka db call, log calls, network request, file read) for a given backend, and allow you to replay those locally for testing purposes independently from the language used by the backend.
I think this didn’t lead anywhere, because it was harder than expected, some things couldn’t be recorded easily (like RNG use), and it also meant finding a way to have all IO libs use the precomputed values.
- danielvaughn 4y agoVery true, yes. Much more useful for existing code. Although I don't think unit tests and TDD necessarily need to be aligned, the red-green-refactor flow could potentially be re-imagined with a tool like this.
- adhesive_wombat 4y agoOne thing I found useful with Trompeloeil was the tracer. You instantiate a tracer, and then every call made into a mocked object is logged for you. Really make it easy to see how a mysterious controller operates on the thing you are mocking. Plus, the very act of engineering in a dependency injection for the mock if not already provided, enforces a testable interface.