beginners

James Amberger 2025-12-01T23:54:53.125219Z

I’m new to testing. If you have the tests for a namespace in a separate file (say under a “test” dir), and you want to use or test a private function, what should you do, other than making the function public?

dpsutton 2025-12-01T23:57:45.757189Z

it’s common to reach around that by var access. (#'ns-prefix/private-var :foo)

dpsutton 2025-12-01T23:58:14.413609Z

others argue pretty strongly that private functions should not be tested, only the api of the namespace.

👀 1
➕ 2
☝️ 1
James Amberger 2025-12-02T00:14:28.851539Z

ok thanks @dpsutton that’s something to think about

Ben Sless 2025-12-02T06:43:00.187889Z

You can rely on a gentlemen's agreement and put all private functions in an impl namespace

👎🏼 1
➕ 1
practicalli-johnny 2025-12-02T08:55:08.256719Z

To expand on the point raised by dpsutton: If a private function is defined then ideally it would be very generic and used by numerous other public functions (the API of the namespace). Therefore any private functions can be covered via tests on those public functions. Testing private functions can make the test suite more brittle to change, take longer to do a test run and increase the overall maintenance of the test suite.

💯 1
teodorlu 2025-12-02T10:01:06.056479Z

I don't remember the last time I wrote a private function! When functions "don't belong" in the namespace, I mostly move them to a different namespace.

James Amberger 2025-12-02T15:02:57.576079Z

yeah I worked on this last night and what you all are saying makes sense; however if the test of the api is “expensive” then that’s maybe one reason or pressure to test the private function directly

James Amberger 2025-12-02T15:04:28.334159Z

like

(defn hit-the-database [db] (db-driver (private-fn-generates-table-name-or-whatever) ...))

James Amberger 2025-12-02T15:10:15.825989Z

any pros/cons for putting the tests in the namespace with the code?

dpsutton 2025-12-02T15:17:08.365259Z

con is that it will be in your artifact. The traditional path is in a separate classpath root that you optionally add in and contains essentially a mirror shape of your namespaces with -test added as a suffix