On Mon, Aug 22, 2022 at 10:31 PM Adam Russell via Boston-pm <
boston-pm@pm.org> wrote:

> I have some networking code in Perl. Fairly low level in that I use raw
> sockets, accept(), etc instead of the higher level IO::Socket package. I'd
> like to test this code but am not sure what the best approach is. There
> doesn't seem to be a convenient testing framework like there is with WWW
> testing. I guess I could use Expect and throw something together but that
> seems a bit clunky.
>
> What I'd like to do is test client(s) connect to port XYZ, sending
> messages, and testing the output returned. Sounds simple enough but it
> isn't clear how to proceed in anything other than a kind of ad hoc way with
> Expect or whatever. Any advice?


You said "*unit testing*" which to me would mean you wanted to *mock* the
socket *accept(), *so it's only testing the logic of the unit under test *per
se, *but then say you want to have an actual socket to port XYZ with stuff
coming back.
Mocking Perl built-ins is awkward but possible, and possibly less awkward .

(The Testing community AFAIK has failed to provide a catchy name for a
single-layer interface test that does tests both a unit under test and the
one layer below the interface it calls, verifying that the two layers agree
on the definition of the interface, which is unfortunate. If someone knows
different, i'd appreciate having the name!)

Is your testing goal to actually see bits move over a tame, pet socket,
or to provide TDD  or regression testing Unit tests for the logic that uses
the socket ?

If both, separating them into Unit and Integration tests is a winning
meta-pattern.

_______________________________________________
Boston-pm mailing list
Boston-pm@pm.org
https://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to