On Thursday, May 16, 2013 11:37:59 AM UTC+3, Niphlod wrote:
>
> the time taken to write something that mocks a database is orders of 
> magnitude more than just testing on a separate database instance.

 
And the execution-time of tests that use a database is 
orders-of-magnitude longer than tests that don't - it's not as 
trivial-a-decision as it seems.
But as I said, the suggestion is not to mock-out the entire 
persistence-layer, that is actually considered a bad idea, because of the 
reasons we both acknowledge.
So the optimal solution should be neither. It should be something 'clever' 
in-between these two extremes.
For example, the 'mock' library provides an api-free approach, that enables 
you to monkey-patch/override a highly-complex set of 
recursive/procedural-calls.
For instance, consider a highly-complex query, such as:

db(db.Budget_BD_Resources.BudgetBD==bd).select(db.Budget_BD_Resources.Amount
.sum(),groupby=db.Budget_BD_Resources.BudgetBD)

You could theoretically monkey-patch this whole statement in it's entirety 
(or any part of it), so it returns whatever you want (say, a pre-made 
'rows' instance with 'row'-instances inside)
The 'mock' library should allow you to do that, wile constraining the 
monkey-patch to a temporary execution-context, and tear-it-off 
automatically at the end of the test (either with a decorator, or a 
context-manager that is provided in the library)
 
 

> As for "decoupling", I'm a big believer that webapp tests should need to 
> be executed with behavioural tests, not unit-tests.
>

Yup! :) 


Of course business logic core modules (if any) can be tested with unittest, 
> but that's actually "outside" the scope of web2py..... they're just 
> standard python modules if you kept them just "business logic" and they 
> don't interfere with presentation logic.
>

Well, that assumes you can completely-decouple the business-logic from code 
that uses the db-object - that's not a trivial-decoupling to accomplish.
Decoupling it from presentation-logic is more trivial usually, but that's 
only half of the story. 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to