Hi James,
On Jan 18, 4:03 pm, James Reeves <[email protected]> wrote:
> 1. I don't like the idea of putting tests next to the functions
> they're testing.
That's cool with me, I won't force you to do it one way or the other.
> 2. Test should come with a description of what scenario they are
> testing, so I favour the RSpec approach of using short descriptive
> strings to identify tests, rather than symbols.
I figure you can use symbols and still make your test names as
descriptive as you like. I did this in the tests for the library
itself, like this:
(deftest can-test-=
(is (= 2 (+ 1 1)) "Should pass")
(is (= 3 (+ 2 2)) "Should fail"))
I think that's how the earliest implementations of behavior-driven
development in Java worked -- they used descriptive method names.
Sure, it's not as pretty, but it works. I also added the "testing"
macro for adding descriptive strings to tests. These can be nested,
as in RSpec:
(deftest arithmetic
(testing "Addition"
(testing "with integers"
(= 2 (+ 1 1))
(= 4 (+ 2 2)))
(testing "with floats"
(= 2.5 (+ 1.0 1.5)))))
This can replace the "test-that" macro that J. McConnell wrote in
clojure/contrib/test_clojure/evaluation.clj. The top-level test name
still has to be a symbol so it can be bound to a Var.
> 3. The biggest problem I've had with tests is generating test data.
Can't help you there, it least not right now. I'm open to suggestions.
> 4. I lean toward the idea that a test should contain a single
> predicate that's tested with numerous inputs.
I've attempted to allow for this with the "are" macro, which takes a
template expression and applies it to a collection of values. The
interface is a little tricky though, so I'm not sure if I should keep
it or not:
(deftest test-my-predicate
(are (my-predicate _1 _2)
... all your test values ...))
The alternative is to use a simple loop:
(deftest test-my-predicate
(let [my-predicate (fn [x y] (is ...whatever...))]
(doseq [[x y] [ ...all your test values ...]]
(my-predicate x y))))
Peace, and happy testing.
-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]
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
-~----------~----~----~----~------~----~------~--~---