Regarding unit testing specifically, I think there are two basic 
approaches. One approach is to slightly modify the way you write and call 
the unit test file, and rely on web2py to build its environment in the 
usual way. This method is described here: 
http://web2py.com/AlterEgo/default/show/260. In that case, rather than 
running the test file directly, you would run it as a web2py script using 
web2py command line options:

python web2py.py -S myapp -M -R applications/myapp/tests/test.py

That will run the test.py test file in the environment of the myapp 
application (including all the models).

Note, the example test.py code executes the controller being tested via:

execfile("applications/api/controllers/10.py", globals())

However, an alternative is to simply specify the controller directly in the 
command line options:

python web2py.py -S myapp/mycontroller -M -R applications/myapp/tests/test.
py

That will run the test.py file in the environment of the mycontroller 
controller of myapp (again, including all the models).

The alternative approach is to write and run unit tests as usual, and 
manually build the needed web2py environment within the unit test itself. 
The web2py Test Runner library was designed with this approach, and it 
includes some methods to make it easy to build the web2py environment 
automatically. See http://packages.python.org/web2py_utils/test_runner.html
 and http://pypi.python.org/pypi/web2py_utils/0.0.13dev.

Finally, for basic testing of controller functions, doctests can be 
included in the controller function docstrings, and the admin interface 
includes functionality to automatically run all such doctests.

Anthony

On Monday, January 21, 2013 3:48:49 PM UTC-5, Israel Fermin Montilla wrote:
>
> Hi there!
>
> I'm new in web2py, I come from programming a lot in django which has built 
> in unit test support
> and I'm kind of a testing freak. There are like 3 or 4 different articles 
> with different approaches
> for testing in web2py and the official documentation of the webclient 
> (which helps a lot by the way),
>
> I would like to know if there is any "official" approach when it comes to 
> testing and, if not, I would
> like to see how could I help, if there is any "contributor guidelines" or 
> any "to-do list", I came into
> web2py in my new job and the first thing that shocked me a little was the 
> DAL (i was so used to the
> django's ORM that at first I hated it), I think testing is very important 
> so, if there is no "official testing
> approach", I would really love to contribute and help to improve the tool 
> I'll be working with now.
>
> Thank you very much and sorry if this is a duplicate.
>

-- 



Reply via email to