Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Testing with non-trivial input

by dws (Chancellor)
on Nov 25, 2004 at 17:50 UTC ( [id://410434]=note: print w/replies, xml ) Need Help??


in reply to Testing with non-trivial input

I want to write a test for method which is going to extract part of an XML file. The input for this is an array of objects which I generate by parsing a CSV file and creating an object for each line.

I'm not clear on what "the input for this" means. Do you mean that you're providing the method under test with a simulated parse?

Would something like the following work?

# ... setup $foo my $xml = <<XML; <?xml version="1.0" encoding="utf-8"?> <stuff> ... </stuff> XML my $out = $foo->method_under_test($xml); ok ( Data::Dumper::Dumper($out), <<EXPECTED ); $VAR1 = { ... }; EXPECTED
That is, provide the raw XML in-line with the test, and also include the expected Data::Dumper output. Tests like this have the benefit of being fairly transparent, even if setting up $foo means creating several objects.

Replies are listed 'Best First'.
Re^2: Testing with non-trivial input
by loris (Hermit) on Oct 12, 2005 at 09:35 UTC

    Hello dws,

    Nearly a year on and I am again faced with this problem. Back then I missed your reply. What you suggest does seem like a good solution. However, wouldn't I have to worry about whitespace issues when defining the expected XML output?

    Thanks,

    loris

    BTW, "the input for this" meant the information about which fragment of XML to extract was contained in a line of the CSV file.

    "It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ."

      wouldn't I have to worry about whitespace issues when defining the expected XML output?

      Yes, but you only have to worry about it once. In fact, it's good to get a test that fails based on whitespace, since examining the output will give you confidence that the test (once the whitespace is corrected) is testing what you expect.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://410434]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found