moll / node-mitm

Intercept and mock outgoing Node.js network TCP connections and HTTP requests for testing. Intercepts and gives you a Net.Socket, Http.IncomingMessage and Http.ServerResponse to test and respond with. Super useful when testing code that hits remote servers.
Other
636 stars 48 forks source link

Record and replay http requests #1

Closed hgoebl closed 10 years ago

hgoebl commented 10 years ago

Would it be possible to extend Mitm in a way so it can be used in a similar way as Betamax? In szenarios where response payloads are quite complex this could save time to develop test cases.

moll commented 10 years ago

Hey!

I haven't thought about it. Haven't actually ever needed something like it either.

How you do solve this problem now? Do a few test requests via wget, curl et al. and see what your remote service responds with?

hgoebl commented 10 years ago

I haven't had this "problem" in node.js projects, only in bigger Java projects. It was handy to put Betamax in record mode and run the tests with the real web/REST services. After recording one can switch the tests to use the recorded data in replay-mode. Betamax creates HAML files which can be edited very easily and put to version control. I thought Mitm might be used for this kind of testing as well. For that it would have to behave like a proxy when in record-mode. For HTTP this should not be a big problem. For Socket and HTTPS I haven't got an idea.

moll commented 10 years ago

Mkay, thanks for your explanation! I can imagine how recording responses might help with getting an understanding of the remote service, but overall as a testing practice I'd be wary of using such big blobs of responses in testing. They're likely not going to be very maintainable. As a general rule, at least when I go about testing, would be to create the response by hand with minimal content, merely enough for a single test to test its assumption. And, likewise, make code handling the response tolerant of missing data.

Inspecting remote service responses to get an understanding is definitely a useful tool, but wouldn't you say existing tools, even as simple as curl, might solve this more easily? Or did you have in mind testing code that you didn't write where you have no idea how the request is even made, let alone the response?

hgoebl commented 10 years ago

You're right with "... minimal content, merely enough for a single test ...". Betamax is a very comfortable tool for tests of more complex software and is well suited for functional tests and tests with pseudo-integration character. For fast, tiny and very focused unit tests, it's better to hand-craft request and response, no question. I suggest you close this issue and when I encounter urgent need for a tool like Betamax for node.js, I'll try to use/extend Mitm in a new project. Thanks for your patience.

moll commented 10 years ago

Cool.

Btw, I believe issue creators can actually close their own issues, too :)

BigAlInTheHouse commented 10 years ago

Thank you.very true.