Connecting Tech Pros Worldwide Forums | Help | Site Map

Assertions in real life

Hugh Oxford
Guest
 
Posts: n/a
#1: Nov 18 '08
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?

Jerry Stuckle
Guest
 
Posts: n/a
#2: Nov 19 '08

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
==================
Christopher Vogt
Guest
 
Posts: n/a
#3: Nov 19 '08

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
Curtis
Guest
 
Posts: n/a
#4: Nov 19 '08

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