On Thu, Sep 15, 2011 at 6:42 AM, Chris Perkins <chrisperkin...@gmail.com>wrote:
> On Wednesday, September 14, 2011 11:19:13 AM UTC-4, Brian Hurt wrote: >> >> Say I have two name spaces, A and B, with A depending on B. I want to >> test namespace A, replacing module B with a mock B for testing purposes- >> preferably without having to load B at all (B sucks in a bunch of stuff, >> like dependencies on databases and external web sites and etc. that I don't >> want to deal with in testing). What is the easy, clojure-approved, >> mechanism for doing this? I tried: >> >> >> > my-project > |-- src > | |-- A.clj > | |-- B.clj > | -- mocks > | |-- B.clj > |-- testdriver.clj > > # Run with the real B: > java -cp clojure.jar:src clojure.main testdriver.clj > > # Run with the mock B: > java -cp clojure.jar:mocks:src clojure.main testdriver.clj > > I don't know if my ascii-art directory tree makes any sense at all, but the > point is that if you put "mocks" earlier in the classpath than "src", then > the mock B > should get loaded instead of the real one. > This is the best answer so far, but it doesn't deal with the three-level case- A depends upon B which depends upon C, and I want to test A without sucking in B and C, and test B without sucking in C. Maybe I'm asking the wrong question. If I have code that naturally structures like: +----------------+ | | | A | | | +----------------+ | | | B | | | +----------------+ | | | C | | | +----------------+ | | | Database | | Or | | Webservice | | Or | | Similar | +----------------+ 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 problem isn't just *writing* the code- I need to be able to change this code later, and have some assurance it still works. So "load it up into a repl and play with it" isn't a viable solution. Or is clojure code just not testable/maintainable? Brian -- 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