Re: [Tutor] More on unit testing - tests for external data...

2009-12-11 Thread Kent Johnson
On Thu, Dec 10, 2009 at 11:19 PM, Modulok  wrote:

> It seems like there are a lot of people on this list interested in
> getting more familiar with unit testing, but not a whole lot of
> non-trivial, python-specific examples being passed around.

> Case studies/tutorials anyone?

Unit testing has become common, accepted practice in open source
projects so real-world examples abound.

Python itself has extensive unit tests. To a large extent they
actually define the language and the libraries - Jython and IronPython
use the CPython test suite to validate their implementations. Download
the Python source to get a copy of the tests.

The Python unit tests largely predate the unittest module so they are
not necessarily good examples of unittest.

I suggest you pick an open source Python project that you use or like
and look at its test suite.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] More on unit testing - tests for external data...

2009-12-10 Thread Modulok
So, this, 'test environment', this is just like a directory where I
place my code and associated files to test for the existence (and
non-existence) of various stuff, right? Any real-world examples/case
studies to point to?

It seems like there are a lot of people on this list interested in
getting more familiar with unit testing, but not a whole lot of
non-trivial, python-specific examples being passed around. I can write
a function in a programming 101 class that accepts two arguments and
returns a value by computing the hypotenuse of a triangle (or
whatever). I can then build a unit-test for that making sure it fails
and passes as needed. Cake. But jump into the real-world where many
things are not so trivial, and I'm at a loss for where this
unit-testing business all fits in.

Basically, I'm trying to become a better programmer. (Who isn't?) I'd
like to transition from 'hacky but gets the job done' or 'oh my God it
actually works' to 'eloquent and bulletproof'. Without some kind of a
mentor or vast array of tutorials to lay down the law when I screw up,
or pass on some kind of approval when I get something right -  it's
been frustrating as hell.

Case studies/tutorials anyone?

Thanks!
-Modulok-

On 12/10/09, spir  wrote:
> Wayne Werner  dixit:
>
>> On Wed, Dec 9, 2009 at 6:15 PM, Alan Gauld
>> wrote:
>>
>> >
>> > Remember, in testing you are not trying to prove it works but rather to
>> > demonstrate that it doesn't!
>> >
>>
>> So in that way it's a bit like the the scientific method (or exactly
>> like)?
>> You create a hypothesis and design tests to invalidate your hypothesis...
>> and if they fail to invalidate you may have a valid hypothesis. Simply
>> replace hypothesis with program and you get the testing procedure?
>>
>> -Wayne
>>
>>
>
> programming is modelizing -- like a scientist's job
>
> Denis
> 
>
> la vita e estrany
>
> http://spir.wikidot.com/
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] More on unit testing - tests for external data...

2009-12-10 Thread spir
Wayne Werner  dixit:

> On Wed, Dec 9, 2009 at 6:15 PM, Alan Gauld wrote:
> 
> >
> > Remember, in testing you are not trying to prove it works but rather to
> > demonstrate that it doesn't!
> >
> 
> So in that way it's a bit like the the scientific method (or exactly like)?
> You create a hypothesis and design tests to invalidate your hypothesis...
> and if they fail to invalidate you may have a valid hypothesis. Simply
> replace hypothesis with program and you get the testing procedure?
> 
> -Wayne
> 
> 

programming is modelizing -- like a scientist's job

Denis


la vita e estrany

http://spir.wikidot.com/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] More on unit testing - tests for external data...

2009-12-10 Thread Kent Johnson
On Thu, Dec 10, 2009 at 11:20 AM, Wayne Werner  wrote:

> On Wed, Dec 9, 2009 at 6:15 PM, Alan Gauld 
> wrote:
>>
>> Remember, in testing you are not trying to prove it works but rather to
>> demonstrate that it doesn't!
>
> So in that way it's a bit like the the scientific method (or exactly like)?
> You create a hypothesis and design tests to invalidate your hypothesis...
> and if they fail to invalidate you may have a valid hypothesis. Simply
> replace hypothesis with program and you get the testing procedure?
> -Wayne

Nice analogy! And like with a scientific hypothesis, you can never be
sure your program is correct, only that all your attempts to prove it
incorrect has failed.

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] More on unit testing - tests for external data...

2009-12-10 Thread Wayne Werner
On Wed, Dec 9, 2009 at 6:15 PM, Alan Gauld wrote:

>
> Remember, in testing you are not trying to prove it works but rather to
> demonstrate that it doesn't!
>

So in that way it's a bit like the the scientific method (or exactly like)?
You create a hypothesis and design tests to invalidate your hypothesis...
and if they fail to invalidate you may have a valid hypothesis. Simply
replace hypothesis with program and you get the testing procedure?

-Wayne


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] More on unit testing - tests for external data...

2009-12-09 Thread Alan Gauld

"Modulok"  wrote


Unit testing functions and methods which rely on passed data is simple
enough. However:

How do I unit test something which relies on external data?


You have to build a test environment.
This needs to be carefully planned to enable every test condition 
to be tested.



For example, a function which creates a file only if it doesn't exist
on disk, or a unit test for a function which makes an SQL query? 


So you would need a file that exists, one that doesn't(!), 
one that exists but is read-only, one that exists but wrong user 
ownership, and really a binary file and a text file and an 
empty file and a huge file too


For the database it gets tricky, you need to create a database 
full of entries with all the possible scenarios you might encounter.
For a large application with multiple joined tables designing such 
a test database can take a lot of time - but it is invaluable for testing 
and debugging and provided you store a clean copy somewhere 
before using it makes regression testing possible.
Once you have the database you then need to write the test driver 
code that will provide the right keys for each test - database testing 
is one of the biggest challenges in system testing.


And don't forget to test for behaviour with invalid user access on 
the database, and for locking and simultaneous updates etc.
And if its on a separate server that you check behaviour when 
the server or network is down or running slowly (eg by lowering 
server priorioty and running a huge bulk update in the background).


Remember, in testing you are not trying to prove it works but rather 
to demonstrate that it doesn't!


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] More on unit testing - tests for external data...

2009-12-09 Thread Modulok
List,

Unit testing functions and methods which rely on passed data is simple
enough. However:

How do I unit test something which relies on external data?

For example, a function which creates a file only if it doesn't exist
on disk, or a unit test for a function which makes an SQL query? If
anyone could point to a few examples of such usage, that would be
great!

Thanks!
-Modulok-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor