Unit Testing in Python

R

rhat

Hi Everyone,
I've recently been reading some articles about unit-testing in Python
[1] [2], but I am a bit confused: where do I go to get started with
this? I tried googling for "unittest" but all I've found are some old
links to projects that already use it, and the older (as the articles
put it) PyUnit project. I'm sorry if this is a obvious question or one
that has already been answered, but unit-testing sounds interesting and
I'm not sure where to start.

Thanks,
Ryan Kaulakis
 
R

Roy Smith

"rhat said:
Hi Everyone,
I've recently been reading some articles about unit-testing in Python
[1] [2], but I am a bit confused: where do I go to get started with
this? I tried googling for "unittest" but all I've found are some old
links to projects that already use it, and the older (as the articles
put it) PyUnit project. I'm sorry if this is a obvious question or one
that has already been answered, but unit-testing sounds interesting and
I'm not sure where to start.

Thanks,
Ryan Kaulakis

PyUnit is indeed what I use. It's included in current distributions as the
"unittest" module.

The module docs aren't perfect (especially when it comes to the big
picture), but there's a good tutorial at
http://diveintopython.org/unit_testing/index.html

Once you get your head around how it works, it's really quite simple to
use. It also has the advantage of being one of a series of "X-unit"
packages for different languages (Junit, C++Unit, etc) which all have the
same organization (with allowances made for language-specific
requirements). This means once you've learned one, you've got a big head
start one learning another one.
 
T

Tom Willis

Neat the original poster shows up as a potential Phisher with a nice
big red warning in gmail.

Due to some funky header fakedness.

Don't give them your SSN. :)

I have a related question. What is PyDoc? I see it come up alot in
searches for Unit testing and python, but I've never gotten around to
finding out why.


Maybe I'll do that now.



rhat said:
Hi Everyone,
I've recently been reading some articles about unit-testing in Python
[1] [2], but I am a bit confused: where do I go to get started with
this? I tried googling for "unittest" but all I've found are some old
links to projects that already use it, and the older (as the articles
put it) PyUnit project. I'm sorry if this is a obvious question or one
that has already been answered, but unit-testing sounds interesting and
I'm not sure where to start.

Thanks,
Ryan Kaulakis

PyUnit is indeed what I use. It's included in current distributions as the
"unittest" module.

The module docs aren't perfect (especially when it comes to the big
picture), but there's a good tutorial at
http://diveintopython.org/unit_testing/index.html

Once you get your head around how it works, it's really quite simple to
use. It also has the advantage of being one of a series of "X-unit"
packages for different languages (Junit, C++Unit, etc) which all have the
same organization (with allowances made for language-specific
requirements). This means once you've learned one, you've got a big head
start one learning another one.
 
R

rhat

Yeah, you know I only ask questions about Test-driven development
basics in hopes of obtaining your personal information, so that I can
sell it on the Molodovian blackmarket. I'm not a "Phisher", I'm a
comp-sci major who's too lazy to dig around for his own answers. ;)

Thanks for your help Roy, I wasn't sure what the difference between
unittest and pyunit were.
--|2 \| /-\ |\| |</-\|_||_/-\|<15 (the uber-l33t version of my
supersecret "phishing" alias which just so happens to be my actual
name)

PS: Yeah, I too am plerplexed as to why gmail allowed me to register
"fakeadmin" as a login. Sure makes a good conversation started though.
=P
 
T

Tom Willis

It could be a bug in gmail. I wasn't actually accusing you, just
thought it was funny enough to point out. Of course you could be more
sarcastic than me who knows. :)

I'm not worried though. I believe the best strategy against Identity
theft is bad credit.

So question , do you see the big red block on your own posts, or have
I been sitting in front of the puter too long?
 
B

Brian van den Broek

rhat said unto the world upon 2005-02-10 21:10:
Hi Everyone,
I've recently been reading some articles about unit-testing in Python
[1] [2], but I am a bit confused: where do I go to get started with
this? I tried googling for "unittest" but all I've found are some old
links to projects that already use it, and the older (as the articles
put it) PyUnit project. I'm sorry if this is a obvious question or one
that has already been answered, but unit-testing sounds interesting and
I'm not sure where to start.

Thanks,
Ryan Kaulakis

Hi,

I've just started learning about testing and TDD, but I found the
following recent articles and blog posts useful:

<http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-unittest.html>
<http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-2-doctest.html>
<http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-3-pytest-tool.html>
<http://www.onlamp.com/lpt/a/5463>
<http://www.onlamp.com/lpt/a/5584>

(Your footnotes didn't come through, so these might not be new to you.)

Best,

Brian vdB
 
R

rhat

Tom said:
It could be a bug in gmail. I wasn't actually accusing you, just
thought it was funny enough to point out. Of course you could be more
sarcastic than me who knows. :)

I'm not worried though. I believe the best strategy against Identity
theft is bad credit.

So question , do you see the big red block on your own posts, or have
I been sitting in front of the puter too long?



I'm glad people have a still have a sense of humor, and yes gmail does
flag mail that I send myself (as in (e-mail address removed) ->
(e-mail address removed)) as being possibly "not from who they claim" I
don't have any other gmail accounts, so I just thought it happened with
all accounts.
 
R

rhat

I actually meant to link to the last two ONLamp articles you mentioned,
so yeah I have seen those (kinda forgot to post them, in fact). Thanks
for the other links too, they look pretty interesting.
Incidentally, what kind of projects are you guys (planning on) using
this technology with? I'm working on educational software, and thought
that it might be neat to try unittest out on. Though, in truth, I don't
know enough about unit-testing to make a design decision that large
yet.

Feel free to [reply | flame the n00b],
Ryan Kaulakis
 
?

=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=

put it) PyUnit project. I'm sorry if this is a obvious question or one
that has already been answered, but unit-testing sounds interesting and
I'm not sure where to start.

Hi Ryan. I belive this (http://www.xp123.com/xplor/xp0201/index.shtml)
is a good way to learn about unit testing by practice if you already
know the basics of it. It is written in Java but is easy to translate
to Python. Unittesting really is great in Python, I try to use it for
anything but simple and dirty hacks.
 
T

Tom Willis

I've had great experience doing Test Driven Development. Ideally you
would do it from the start, but it is great for refactoring as well.
In any language.

One of the pitfalls to look out for is to not get too hung up on it.
In the end it's just a tool you use at your discretion. When I first
started doing it, I would get hung up on how the test framework should
look etc... almost as if I was architecting a system. It really slowed
me down.

I now take this approach...

1. what is the smallest piece of functionality that I want? (What to test)
2. what test will confirm I have this functionality?(How to test it)
3. how will I access this functionality.(Define the API)
4. write test
5. write code
6. run test.
7. repeat 4,5,6 until you're happy.

Frameworks like xUnit etc... just enhance the experience but are in no
way required in my opinion.

Another nice side effect is that your architecture design then comes
naturally and it is exactly what you need nothing more, nothing less.

I recently converted a very problematic data migration routine that
was written in Transact SQL by a consultant who liked to push the
limits of their chosen tool.

I wrote it in Python because I was predicting that no one could nail
down all the possible permutations of data that might come through. I
needed the ability for the routine to be flexible.

Anywho, using python and TDD I was able to get functionality
running/tested from minute 1 using only XEmacs and ipython.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top