Re: [web2py] Unit Testing Database Best Practices

288 views
Skip to first unread message

Richard Vézina

unread,
Jul 23, 2012, 10:40:51 AM7/23/12
to web...@googlegroups.com
I am interesting in what will come out of this thread...

But, to me I think your last question on fact that database will have undertermined set of data mean that you maybe not validate your app base on the entries of the database but on a testing database with a set of known data, that you can even charge on need for the test. Also, you will just test the limit with data that will for example help to demonstrate that a field type is appropriately defined to get all type of data you intend to put in in. Count, if variable get creates, etc., is more in the basic thing you can always check for every function...

I am also pretty new to unit test in general and have most the same questions.

Cheers!

Richard


On Sun, Jul 22, 2012 at 9:41 PM, Mark Li <markru...@gmail.com> wrote:
I'm fairly new to test-driven development and have decided it is the best way to go for my new webapp. While functional tests with selenium seem to be more straightforward (as far as what the tests want to accomplish), I'm lost on what unit tests for the database should test for.

For example, if I have a database table with columns id, 'dogowner', and 'dogname', and have a controller returning a dict with 'dogowners', what should I be testing in the unit tests for the database and controller?

The database table will be fixed with a limited number of 'dogowner' entries, about 10, so should I be testing whether the database has 10 entries, and if the len of the dict returned by the controller is 10? This datatable may not be fixed in the future, so what functionality of the database would I be testing for?



I'm following http://www.web2py.com/AlterEgo/default/show/260 , but while that page explains HOW to go about unit testing, it doesn't explain what I should be testing for. Anyone experienced with TDD in web2py want to point me in the right direction? Thanks in advance!

--
 
 
 

vinic...@gmail.com

unread,
Jul 23, 2012, 12:37:15 PM7/23/12
to web...@googlegroups.com
+1
> --
>
>
>

Mark Li

unread,
Jul 23, 2012, 2:49:38 PM7/23/12
to web...@googlegroups.com
Thanks Richard, for now I am going to create a special database table that will follow the structure of the actual data tables, but with a fixed data set like you suggested (controls for count very well).

I'm still interested in any real examples people use for unit testing databases and controller functions, I'm sure i'm glossing over something!

Martín Mulone

unread,
Jul 23, 2012, 3:13:07 PM7/23/12
to web...@googlegroups.com
that guide is too old, have execfile() :S. Search in the group on how to use modules in your app.

2012/7/22 Mark Li <markru...@gmail.com>

I'm fairly new to test-driven development and have decided it is the best way to go for my new webapp. While functional tests with selenium seem to be more straightforward (as far as what the tests want to accomplish), I'm lost on what unit tests for the database should test for.

For example, if I have a database table with columns id, 'dogowner', and 'dogname', and have a controller returning a dict with 'dogowners', what should I be testing in the unit tests for the database and controller?

The database table will be fixed with a limited number of 'dogowner' entries, about 10, so should I be testing whether the database has 10 entries, and if the len of the dict returned by the controller is 10? This datatable may not be fixed in the future, so what functionality of the database would I be testing for?



I'm following http://www.web2py.com/AlterEgo/default/show/260 , but while that page explains HOW to go about unit testing, it doesn't explain what I should be testing for. Anyone experienced with TDD in web2py want to point me in the right direction? Thanks in advance!

--
 
 
 



--

Richard Vézina

unread,
Jul 23, 2012, 4:17:21 PM7/23/12
to web...@googlegroups.com
I know it is not exactly what you want, but there is this tutorial for TDD and web2py : 


Richard

--

--
 
 
 

Richard Vézina

unread,
Jul 23, 2012, 4:22:31 PM7/23/12
to web...@googlegroups.com

Mark Li

unread,
Jul 23, 2012, 9:30:58 PM7/23/12
to
Regarding Martin's response for anyone who is learning the ropes like me, I removed the execfile() line and placed my unit_test.py script in the module folder.

EDIT: I've run into the problem of getting the controllers functions recognized in my unit test script.

I'm running the test with this command line

python.exe -u web2py.py -S appname -M -R applications/appname/modules/unit_test.py

However this only exposes the models, not the controllers. How would I go about running the test in a web2py environment that exposes the controller functions, without the use of execfile()?
Reply all
Reply to author
Forward
0 new messages