Connecting Tech Pros Worldwide Help | Site Map

Assertions in real life

  #1  
Old November 18th, 2008, 10:55 PM
Hugh Oxford
Guest
 
Posts: n/a
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?
  #2  
Old November 19th, 2008, 12:55 AM
Jerry Stuckle
Guest
 
Posts: n/a

re: Assertions in real life


Hugh Oxford wrote:
Quote:
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?
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
==================
  #3  
Old November 19th, 2008, 07:45 AM
Christopher Vogt
Guest
 
Posts: n/a

re: Assertions in real life


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
  #4  
Old November 19th, 2008, 08:25 AM
Curtis
Guest
 
Posts: n/a

re: Assertions in real life


On Tue, 18 Nov 2008 22:51:01 +0000, arestes@fas.com wrote:
Quote:
I am told that I should use assertions in my testing. [...]
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.
Quote:
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?
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);
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Too Many Assertions? Jefffff answers 8 March 29th, 2006 04:35 PM
Quest: Using Resource in C# app... bj7lewis answers 12 November 17th, 2005 04:30 AM
declarations summary Michael Tobis answers 9 July 18th, 2005 10:16 PM
Python syntax in Lisp and Scheme mike420@ziplip.com answers 699 July 18th, 2005 05:41 AM