On Friday, September 16, 2011 3:12:49 PM UTC-4, Brian Hurt wrote:
>
> How *should* I structure this code for testing?  I was assuming the natural 
> way to do this is to make A, B, and C separate name spaces but maybe this is 
> wrong.


The best way to make these namespaces testable, in my opinion, is remove the 
dependencies. In the ideal scenario, only the bottom layer -- layer C in 
your diagram -- would have any side-effects. Layer B -- the middle layer -- 
would consist entirely of pure functions that operate on the data structures 
generated and consumed by C, but would have no direct dependencies on C. 
Finally, layer A would tie the two together. I wrote about this approach 
here: http://stuartsierra.com/2011/08/08/clojure-namespaces

In this style, layer B is easy to unit-test. Tests for layer C are 
"integration" tests that know about external services like databases. Tests 
for layer A are whole-application tests.

Another option is to design the APIs of B and C around an object that 
represents the runtime environment. The testing environment returns mock 
data; the production environment uses the real functions. This object could 
be an argument to functions in B and C, or it could be a Var bound to a 
special value for testing.

-Stuart Sierra
clojure.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to