Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm just confused, I guess what I'm really looking for is "real world" examples of tests for complex things, things you can't just test by calling a function and comparing it's output to a constant.

If you approach development by considering the test first--thinking through how to structure a method, class, or API such that it's possible to call functions and compare output--you'd be surprised how far you can get. Part of the trick is being clear about what you're testing. You want to test small numbers at a things at a time, faking whatever infrastructure those things live on top of.

Take your example. You're building a web application that manipulates a specific kind of server. The "obvious" way to test such a think is to simulate an input (a link click or a button press), then verify that the right HTML comes back. But these kind of tests end up testing too much stuff at once, and get messy quickly. It's far easier to break things down and test parts in semi-isolation. Not knowing how your application is structured, I can speculate that you have a layer that abstracts communication to the remote server. This layer can be tested in isolation, even in isolation from a real remote server, if there's a way to swap in a "mock" object for the remote server (e.g., by using a fake socket that's under the control of the test code). Then, you can write test cases that verify that if you tickle the abstraction API, the write bits get delivered to the socket. And you can test that the server abstraction correctly handles various simulated responses from the remove server.

Then, you can test whatever layer drivers the remote server abstraction by swapping in a mock implementation of the abstraction layer. And so on up the chain, small piece by small piece, until you're at the level of delivering test-driven URIs to the top layer of code, and are verifying that it's emiting the HTML you expect.

The trick is to figure out how to structure the code so that you can swap in mock implementations of underpinnings. This is a lot easier to do if you approach development by figuring out the test case first, but can still be done on legacy code with some amount of restructing.


In reply to Re: Yet another meditation on testing by dws
in thread Yet another meditation on testing by BUU

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found