Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9146935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:51:59+00:00 2026-06-17T10:51:59+00:00

In my Clojure codebase, I have defined several protocols and several defrecords. I am

  • 0

In my Clojure codebase, I have defined several protocols and several defrecords. I am using clojure.test to unit test the concrete functions defined within my defrecords.

For example, let’s say I have the following source files:

In src/foo/protocols.clj:

(ns foo.protocols)

(defprotocol RequestAcceptability
  (desired-accepted-charset [this]))

In src/foo/types.clj:

(ns foo.types
  (:use [foo.protocols :only [RequestAcceptability desired-accepted-charset]])

(defrecord RequestProcessor
  [field-1 field-2]
  RequestAcceptability
  (desired-accepted-charset [this]
    ...implementation here...))

In test/foo/types_test.clj:

(ns foo.types-test
  (:use [clojure.test])
  (:use [foo.protocols :only [RequestAcceptability desired-accepted-charset]])
  (:import [foo.types RequestProcessor]))

(deftest test-desired-accepted-charset_1
  ...test code here...)

I am using Clojure 1.4, Leiningen 2, nrepl within Emacs.

The annoyance I am facing is that when I go to run my unit tests (e.g., using C-c C-, sequence), I get a ClassNotFoundException: foo.types.RequestProcessor. To get around this, I’m doing the manual work of evaluating, individually, each of my protocol and defrecord forms. I.e., I’ll navigate over to my protocols.clj and evaluate (C-M-x key sequence for nrepl) my defprotocol form; and then I’ll navigate to my types.clj and evaluate my defrecord form; and then finally I’m able to successfully run my unit tests w/out getting the ClassNotFoundException.

Of course, in my real code base, I have to do this for all my protocols and defrecords, and so it is very tedious and time consuming. Also, if I simply drop to a shell and do lein test, I get the same ClassNotFoundException.

Is there a better way?

Thank you for your time and help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:52:01+00:00Added an answer on June 17, 2026 at 10:52 am

    You need to require the namespace that contains the defrecord in your test namespace.

    (:import [foo.types RequestProcessor])) won’t work on its own, since that only works for Java classes that already exist on the classpath. This isn’t the case here, since you are using defrecord to dynamically create the class at runtime.

    import is usually only needed for Java interop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in clojure i have vector [myfn1 myfn2 myfn3] how can i call functions named
So in my JavaScript codebase I have been using the var me = this
Using clojure I have a very large amount of data in a sequence and
In clojure, keywords evaluate to themselves, e.g.: >>:test :test They don't take any parameters,
Clojure macro noob here. I have a function with some optional parameters, e.g. (defn
In Clojure, (def x 3) (eval '(prn x)) prints 3, whereas (let [y 3]
Using clojure, I've been able to successfully setup log4j very simply by using this
In clojure, how do I type type hint a type that I have created?
More Clojure weirdness. I have this function I'm trying to define and call. It
The Clojure API describes these two functions as: (send a f & args) -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.