On Jul 14, 9:41 am, Matt Revelle <[email protected]> wrote:
> I recently noticed that fixtures were not being called for some tests  
> in my code and it turns out (thanks, Chouser) the use of test-ns-hook  
> is incompatible with fixtures.  This isn't necessarily undesirable  
> behavior, but it raises an issue: does anyone want high-level support  
> for grouping and ordering tests while using fixtures to setup and tear  
> down test resources?

Hi Matt,
You're right; it doesn't work.  Fixtures were added later, long after
test-ns-hook, and I never used them together.

Something I've been meaning to do is replace "test-ns-hook" with
metadata on the namespace.  But that still won't solve the fixture
problem.

Namespace-wide fixtures ("once-fixtures") are easy -- they should just
run around the top-level test function.  That's something I can fix,
and it will be sufficient for your example.

But per-test fixtures ("each-fixtures") present a problem.  If the
fixtures are run around every test function, then they will be called
multiple times when test functions are nested.  Should they be called
just around the top-level test functions, or just around the bottom-
level test functions?  And how do you determine where the "bottom" of
the test function hierarchy is?

I don't know the answers to these questions.  So for now, my solution
is: if you want to compose tests by calling them as functions, then
you should implement your own fixtures using macros, like this:

(defmacro with-db [& body]
  `(... set-up ...
    ~...@body
    ... tear-down ...)))

(deftest foo
  (with-db ...))

That way you can decide exactly where the fixture should be run.  This
is how I used to do fixtures before implementing them in the testing
library.

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

Reply via email to