Thursday, July 27, 2006

OSCON: Day two part 4

After a break in the exhibit hall, during which I talked to people in the Oregon booth about getting Shopzilla to open a Portland office, we split up for more talks. I attended the "Live Perl Testing" talk, which featured a fellow writing tests live for the audience while another narrated. They started with a contrived example but moved on quickly to the bulk of the presentation, in which they took a script from Matt's Script Archive (a resource famous for it's terribly amateurish Perl code) and retrofitted it with a test suite. This is a very clever approach for illustrating how old, terrible code can be tested and subsequently refactored.

One tip they provided for testing existing code involves using the Test::Output module, which simply verifies that a piece of code emits some data to STDOUT. It's a quick way to verify some functionality of existing code, but obviously is not a long-term approach. However it can be an easy way to enable refactoring for some programs.

Next up was creating mock input, which they did by using the tie builtin:
tie *STDIN, 'IO::Scalar', \$input;


Things got weird for a second when they mocked a method in the class they were testing. I had to ask a couple of questions before I understood the purpose was to provide a way for other code to use that method internally without messing with the results. The difficulty (for me) came from the fact that their example was so contrived that it was technically a no-op in that context. Luckily they were able to explain this for me, and we moved on. It might have helped me if they had been more explicit by using a mock module to do it. Instead they used some Perl voodoo to accomplish the task, which struck me as a bad idea, but I think they were being intentionally pedantic to illustrate a point.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home