Click here to get back home

Assertions in real life

 HomeNewsGroups | Search

comp.lang.php - PHP programming language discussions 

get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Assertions in real life Hugh Oxford 11-18-2008
Posted by Hugh Oxford on November 18, 2008, 5:51 pm
Please log in for more thread options
I am told that I should use assertions in my testing. The problem is,
because I test using a cut of live data, the data always changes. Has
anyone come up against this or have they abandoned assertions generally?

On a more general note, how does one reconcile a changing data set with
testing driven development?

Posted by Jerry Stuckle on November 18, 2008, 7:50 pm
Please log in for more thread options
Hugh Oxford wrote:
show/hide quoted text

You need to validate external data. Whether you use assertions or
another means is up to you. But the data do need to be validated.

You should know what data are valid, and what are invalid, and need to
verify that valid data are accepted and invalid data rejected by your
scripts.

This isn't just in PHP - it's in any program and language. It's just
good programming practice.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Posted by Christopher Vogt on November 19, 2008, 2:38 am
Please log in for more thread options
Hej Hugh,

for unit tests assertions are a common thing.

In case you don't know what unit tests are, please read about them. Look
for "simpletest" or "phpunit".

Normally tests should provide their own data to run against the unit to
be tested.

If this doesn't fit to your problem, provide more information.

Chris

Posted by Curtis on November 19, 2008, 3:24 am
Please log in for more thread options
On Tue, 18 Nov 2008 22:51:01 +0000, arestes@fas.com wrote:
show/hide quoted text

Assertions are not meant to be a form of error handling, and
generally should never be present in production code. They aren't
necessary, but can sometimes be helpful for sanity checks.

Assertions can be helpful when doing something like testing some
expression that, logically, should not fail. Take another example:
in C programming, it can be helpful to use assertions to ensure you
don't try to dereference NULL pointers (you should never do this),
thus making it easier to catch undefined behavior, letting you know
exactly where the problem occurred, should the assertion fail.

show/hide quoted text

This seems to be a bit of a vague question. You should have an idea
of the type of data your application needs. You should then take
necessary steps to validate and/or sanitize the data appropriately.
Make sure to only escape data appropriately during output as well.
It's often easier to store raw data, and only escape as necessary.

--
Curtis
$email = str_replace('sig.invalid', 'gmail.com', $from);

Similar ThreadsPosted
Why php gettext is needed in real life? June 3, 2008, 1:06 pm
the AIM of LIFE September 24, 2007, 3:47 am
hi hi hi its about your life February 12, 2008, 7:41 am
Life Webmaster January 31, 2007, 1:27 pm
php4 end of life February 17, 2007, 9:19 am
!very important for your life... March 27, 2009, 12:09 pm
!very important for your life... March 28, 2009, 5:42 am
Usenet Beavis: This is your life[tm]! October 23, 2006, 7:07 pm
Life is Different here, sky has no limit but you must grip it with this website, December 19, 2006, 2:19 pm
Re: Life time of a Initialized object June 11, 2008, 12:02 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Driving a better car - Fuelzilla.com

Cabling site for homeowners and pros alike - Cabling-Design.com

Friends:

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap
Privacy Policy