[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Unit testing Web applications

Monica Leko

3/5/2008 3:37:00 PM

Hi!

Does Python has some testing frameworks for testing Web applications
(like Cactus and HttpUnit for Java), generating requests and checking
if the response is correct?
2 Answers

Diez B. Roggisch

3/5/2008 4:04:00 PM

0

Monica Leko wrote:

> Hi!
>
> Does Python has some testing frameworks for testing Web applications
> (like Cactus and HttpUnit for Java), generating requests and checking
> if the response is correct?

mechanize and webunit come to my mind.

Yet the most powerful will be selenium together with selenium-remote driven
via python. Don't forget to check out the brilliant selenium IDE.

Diez

Ryan Ginstrom

3/6/2008 1:52:00 AM

0

> On Behalf Of Monica Leko
> Does Python has some testing frameworks for testing Web
> applications (like Cactus and HttpUnit for Java), generating
> requests and checking if the response is correct?

I have got a lot of traction using mechanize [1] with nose [2]. Of course
that still leaves out testing JavaScript. For that, something like PAMIE [3]
is one way to go.

[1] http://wwwsearch.sourceforge.net/...
[2] http://somethingaboutorange.com/mrl/proj...
[3] http://pamie.source...

Here's an example of how I use mechanize + nose:

# test_index.py
from mechanize import Browser

class TestPageLoads:

def setup(self):
self.mech = Browser()
self.mech.set_handle_robots(False) # use thought and
consideration...

def test_nonexistent(self):
try:
response =
self.mech.open("http://honyaku-archive.org/nonexist...)
assert False, "Should have thrown here"
except Exception, e:
assert "404" in str(e), e

def test_index(self):
response = self.mech.open("http://honyaku-archive....)
assert response.code == 200, response.code

def test_index_title(self):
response = self.mech.open("http://honyaku-archive....)
assert self.mech.title().strip() == "Honyaku Archive :: Home",
self.mech.title()

Regards,
Ryan Ginstrom