Re: testing local functions?

2010-09-10 Thread James Reeves
On 10 September 2010 12:24, alux alu...@googlemail.com wrote:
 I always thought it to be good style to make helper functions only as
 visible as needed, e.g. by using letfn.

 But when I want to test my code, I just dont see a way to access these
 local functions for tests.

I don't believe you can. You could make them private functions, and
then test them by referring directly to their vars, e.g.

(#'your.namespace/private-function ...)

But in general, your tests should be testing your public interface,
not a specific implementation. Your tests shouldn't care what your
code does behind the scenes, so long as the publicly accessible
functions return the correct result.

- James

-- 
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


Re: testing local functions?

2010-09-10 Thread alux
Hi James,

thanks for your answer.

 your tests should be testing your public interface

Hhmmm.
Well, I tend to disagree here. I sometimes like to have tests in place
for things I want to refactor. To not inadvertently do something
foolish.

But I agree that this is not easily accomplishable.

Greetings, alux

On 10 Sep., 13:39, James Reeves jree...@weavejester.com wrote:
 On 10 September 2010 12:24, alux alu...@googlemail.com wrote:

  I always thought it to be good style to make helper functions only as
  visible as needed, e.g. by using letfn.

  But when I want to test my code, I just dont see a way to access these
  local functions for tests.

 I don't believe you can. You could make them private functions, and
 then test them by referring directly to their vars, e.g.

 (#'your.namespace/private-function ...)

 But in general, your tests should be testing your public interface,
 not a specific implementation. Your tests shouldn't care what your
 code does behind the scenes, so long as the publicly accessible
 functions return the correct result.

 - James

-- 
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


Re: testing local functions?

2010-09-10 Thread Christian Vest Hansen
From someone who's window to your code is your public API, a
refactoring should make no observable change.

So if you only test on the public API, but you test it thoroughly,
then your tests will ensure that this property holds.

Tests that delve into implementation details and private things, are
more brittle because they are affected by changes in implementation
details.

On Fri, Sep 10, 2010 at 14:16, alux alu...@googlemail.com wrote:
 Hi James,

 thanks for your answer.

 your tests should be testing your public interface

 Hhmmm.
 Well, I tend to disagree here. I sometimes like to have tests in place
 for things I want to refactor. To not inadvertently do something
 foolish.

 But I agree that this is not easily accomplishable.

 Greetings, alux

 On 10 Sep., 13:39, James Reeves jree...@weavejester.com wrote:
 On 10 September 2010 12:24, alux alu...@googlemail.com wrote:

  I always thought it to be good style to make helper functions only as
  visible as needed, e.g. by using letfn.

  But when I want to test my code, I just dont see a way to access these
  local functions for tests.

 I don't believe you can. You could make them private functions, and
 then test them by referring directly to their vars, e.g.

 (#'your.namespace/private-function ...)

 But in general, your tests should be testing your public interface,
 not a specific implementation. Your tests shouldn't care what your
 code does behind the scenes, so long as the publicly accessible
 functions return the correct result.

 - James

 --
 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



-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

-- 
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


Re: testing local functions?

2010-09-10 Thread Brian Marick
I've worked out a way to test local functions. When I tried it out by hand, it 
felt good. See here: http://bit.ly/b1AoG7

Implementing it is on my wishlist for Midje, my test framework. 
http://github.com/marick/Midje



On Sep 10, 2010, at 6:24 AM, alux wrote:

 Hello,
 
 I always thought it to be good style to make helper functions only as
 visible as needed, e.g. by using letfn.
 
 But when I want to test my code, I just dont see a way to access these
 local functions for tests.



-
Brian Marick, independent consultant
Mostly on agile methods with a testing slant
Author of /Programming Cocoa with Ruby/
www.exampler.com, www.exampler.com/blog, www.twitter.com/marick

-- 
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


Re: testing local functions?

2010-09-10 Thread alux
Brian, thats way cool!

(I still have to think this through, thats high magic!)

Thank you for sharing this, and kind regards, alux

On 10 Sep., 21:04, Brian Marick mar...@exampler.com wrote:
 I've worked out a way to test local functions. When I tried it out by hand, 
 it felt good. See here:http://bit.ly/b1AoG7

 Implementing it is on my wishlist for Midje, my test 
 framework.http://github.com/marick/Midje

 On Sep 10, 2010, at 6:24 AM, alux wrote:

  Hello,

  I always thought it to be good style to make helper functions only as
  visible as needed, e.g. by using letfn.

  But when I want to test my code, I just dont see a way to access these
  local functions for tests.

 -
 Brian Marick, independent consultant
 Mostly on agile methods with a testing slant
 Author of /Programming Cocoa with 
 Ruby/www.exampler.com,www.exampler.com/blog,www.twitter.com/marick

-- 
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