Discussion:
How to unit test (defn-) functions?
Hussein B.
2014-06-12 08:44:21 UTC
Permalink
Hi,

I like to use (defn-) when it comes to internal implementation functions.
But since they aren't exposed, how to unit test them?

Of course, I'm using Lein and clojure.test

Thanks.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to ***@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+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ray Miller
2014-06-12 08:53:22 UTC
Permalink
Post by Hussein B.
Hi,
I like to use (defn-) when it comes to internal implementation functions.
But since they aren't exposed, how to unit test them?
Of course, I'm using Lein and clojure.test
It feels like a bit of a hack, but:

(#'other-ns/private-fn ...)

should get you by.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to ***@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+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
James Reeves
2014-06-12 12:14:23 UTC
Permalink
Post by Hussein B.
I like to use (defn-) when it comes to internal implementation functions.
But since they aren't exposed, how to unit test them?
Generally speaking it's a bad idea to unit-test private functions (in any
language), as they're implementation details.

- James
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to ***@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+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
mynomoto
2014-06-12 13:53:13 UTC
Permalink
You can use a macro. Look how on
http://nakkaya.com/2009/11/18/unit-testing-in-clojure/
Post by Hussein B.
Hi,
I like to use (defn-) when it comes to internal implementation functions.
But since they aren't exposed, how to unit test them?
Of course, I'm using Lein and clojure.test
Thanks.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to ***@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+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Timothy Baldridge
2014-06-12 14:33:11 UTC
Permalink
I say this too many times on this list, but I'll say it again. The best way
to test defn- functions is to never use defn- in the first place. Instead
move implementation functions into an internal namespace that way they can
be accessed if needed, but are out of the way of the public api. It also
makes it easier for your users to tap into the core of your
library/application if needed. Trust your users to make good decisions,
make everything public, separate via namespaces.

For an example of this see: http://github.com/clojure/core.async

Timothy
Post by mynomoto
You can use a macro. Look how on
http://nakkaya.com/2009/11/18/unit-testing-in-clojure/
Post by Hussein B.
Hi,
I like to use (defn-) when it comes to internal implementation functions.
But since they aren't exposed, how to unit test them?
Of course, I'm using Lein and clojure.test
Thanks.
--
You received this message because you are subscribed to the Google Groups "Clojure" group.
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to ***@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+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
J Irving
2014-06-12 14:44:00 UTC
Permalink
Hey Timothy

So I honestly don't mean to be a smart ass, but there are 6 defn- functions
in clojure.core.async - how do you test those? Or are they just considered
internals to other public functions?

cheers, J
Post by Timothy Baldridge
I say this too many times on this list, but I'll say it again. The best
way to test defn- functions is to never use defn- in the first place.
Instead move implementation functions into an internal namespace that way
they can be accessed if needed, but are out of the way of the public api.
It also makes it easier for your users to tap into the core of your
library/application if needed. Trust your users to make good decisions,
make everything public, separate via namespaces.
For an example of this see: http://github.com/clojure/core.async
Timothy
Post by mynomoto
You can use a macro. Look how on
http://nakkaya.com/2009/11/18/unit-testing-in-clojure/
Post by Hussein B.
Hi,
I like to use (defn-) when it comes to internal implementation
functions. But since they aren't exposed, how to unit test them?
Of course, I'm using Lein and clojure.test
Thanks.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)
--
You received this message because you are subscribed to the Google Groups "Clojure" group.
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to ***@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+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Timothy Baldridge
2014-06-12 14:52:39 UTC
Permalink
There are 6 defn-'s in there? Rich must have wrote that code :-P .

But yes, defn- is mostly used in clojure.core and other such libraries for
functions that are created to simplify other functions. And I would
probably never test those.

Even then I would caution about using defn- too much as some have pointed
out functions like clojure.core/assert-args is kindof handy, but it's
private, so you can't touch it.

Also, core.async tends to take a "in the large" view of testing. For
example, the guts of the go macro are never tested. Instead the macro is
tested in about 50 different ways. The idea being that if a single one of
those tests fail it's easy to figure out what's wrong based on what passes
and fails.

Timothy
Post by J Irving
Hey Timothy
So I honestly don't mean to be a smart ass, but there are 6 defn-
functions in clojure.core.async - how do you test those? Or are they just
considered internals to other public functions?
cheers, J
Post by Timothy Baldridge
I say this too many times on this list, but I'll say it again. The best
way to test defn- functions is to never use defn- in the first place.
Instead move implementation functions into an internal namespace that way
they can be accessed if needed, but are out of the way of the public api.
It also makes it easier for your users to tap into the core of your
library/application if needed. Trust your users to make good decisions,
make everything public, separate via namespaces.
For an example of this see: http://github.com/clojure/core.async
Timothy
Post by mynomoto
You can use a macro. Look how on
http://nakkaya.com/2009/11/18/unit-testing-in-clojure/
Post by Hussein B.
Hi,
I like to use (defn-) when it comes to internal implementation
functions. But since they aren't exposed, how to unit test them?
Of course, I'm using Lein and clojure.test
Thanks.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
Note that posts from new members are moderated - please be patient with
your first post.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Clojure" group.
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to ***@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+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sean Corfield
2014-06-12 22:40:28 UTC
Permalink
Post by Timothy Baldridge
I say this too many times on this list, but I'll say it again. The best way
to test defn- functions is to never use defn- in the first place. Instead
move implementation functions into an internal namespace that way they can
be accessed if needed, but are out of the way of the public api.
Just a note that I got essentially the opposite feedback from
Clojure/core about java.jdbc some time back. It had an implementation
namespace and an API namespace, and when I asked for feedback and what
needed to be addressed before considering a 1.0.0 release (yes, I was
planning well ahead), they said not to have a separate implementation
namespace. So java.jdbc is one namespace, with implementation details
as private functions now.
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to ***@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+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
r***@gmail.com
2014-06-14 17:32:38 UTC
Permalink
Always test private functions through public ones. They have to use them.
Private stuff should appear during refactoring phase.
Post by Hussein B.
Hi,
I like to use (defn-) when it comes to internal implementation functions.
But since they aren't exposed, how to unit test them?
Of course, I'm using Lein and clojure.test
Thanks.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to ***@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+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...