in reply to Best Approach: package module tests with tcp

Test everything in isolation. That usually means test each function and method separately. For something complicated, you'll want to test as many pieces together as possible, but I never do that before I've tested everything in isolation.

If I were doing this, I'd pull out the trusty Test::MockObject, fake up a network client (since it now works with blessed filehandles, you're golden), and test the slimmest bits of network code as possible.

Another option is to have Makefile.PL check if you're in interactive mode and prompt to connect to a known server. That's a good integration test -- it's what CPAN does.

My first answer is still, "test each piece individually" because most of your code doesn't actually rely on the network.

  • Comment on Re: Best Approach: package module tests with tcp

Replies are listed 'Best First'.
Re: Re: Best Approach: package module tests with tcp
by jk2addict (Chaplain) on Jan 24, 2003 at 18:35 UTC

    My apologies, but how to test using Test::MockObject seems simple according to the documentation. Where I fall down however is what and how to test in context.

    Testing an object that munges text or does calculations is pretty straight forward I would think. You know the in and out going into the test. But what about a network client in which there isn't one method to test, but instead it's the whole connect/send/receive/disconnet conversation that needs to be tested? It is at that point that I don't understand or have a clue where to start, esp without a server to conect to or a mock server to use.

    -=Chris

      If something's hard to test, that's a sign that it could be simpler. Break it into smaller pieces based on logical behavior. If you have a function that connects to a socket and logs some data and prints some data, turn it into three functions.

      I'd start with the functions that only expect a live socket connection to be passed in, mock one up, and see what happens there.