Testing PHP Csv Utilities - use real csv files?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Testing PHP Csv Utilities - use real csv files?

Post by Luke »

I have decided to rewrite my unit tests for PHP CSV Utilities before releasing version 0.3. One thing that I've been wondering about is how to test my auto-detector and even my reader. Should I be using actual csv files? Should I be somehow "mocking" a csv file? It seems to me that testing with actual csv files is somehow more related to smoke testing. Am I wrong?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Testing PHP Csv Utilities - use real csv files?

Post by onion2k »

When I test code that handles files I usually make a bunch of files that represent all the different styles and types of files the code needs to deal with. For example, I have a standard directory of test images in different formats, resolutions, landscape/portrait, etc.

No idea if that's a 'standard' way of doing things mind you. It's just what works for me.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Testing PHP Csv Utilities - use real csv files?

Post by Luke »

Yea that's exactly what I've done. I have a list of files in my tests called "bad-delimiter.csv", "commas-100-lines.csv", etc. I guess that's really the only way, eh?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Testing PHP Csv Utilities - use real csv files?

Post by onion2k »

You could write unit tests that test the code against those files I guess. I did that for one of my image projects.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Testing PHP Csv Utilities - use real csv files?

Post by Luke »

Yep, that's how I'm doing it now. I just wasn't sure if that was right. So what is a smoke test then? :?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Testing PHP Csv Utilities - use real csv files?

Post by josh »

You have to be careful that if you write data to a file in one test, that the file gets reset before the next test, otherwise your tests will get too coupled to be meaningful
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Testing PHP Csv Utilities - use real csv files?

Post by Luke »

Oh yea of course... I do that in my setUp and tearDown() methods. Good advice though... thanks :)
Post Reply