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 8392543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:32:33+00:00 2026-06-09T19:32:33+00:00

I am trying to write a unit test for my :pre and :post conditions,

  • 0

I am trying to write a unit test for my :pre and :post conditions, and my first thought was to do this:

(ns myproj.battle-test
  (:use clojure.test
        myproj.battle))

(deftest lose-only-positive-amount-of-health
  (let [actor {:health 100}]
    (is (thrown? AssertionException
          (:health (lose-health actor -5))))))

But I can’t work out how to reference AssertionException from my test file, and get an exception instead:

java.lang.IllegalArgumentException: Unable to resolve classname: AssertionException

I’ve tried various things (and Google hasn’t been helpful, presumably because this is far too simple a question) but without any luck, so how do I check that AssertionException was thrown?

I realise this is very much a beginner’s question; these are my first few lines of Clojure 🙂

  • 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-09T19:32:34+00:00Added an answer on June 9, 2026 at 7:32 pm

    Exceptions are classes, so just import it.

    (ns myproj.battle-test
      (:use clojure.test
            myproj.battle)
      (:import a.package.which.contains.AssertionException))
    ...
    

    Locate where (in which package) AssertionException is located and substitute it instead of a.package.which.contains in the code above.

    Or you can use full name instead, just like in :import clause above, but this can be tedious if you have more than one places where you use the class.

    UPD. I made a mistake. There is no such class, AssertionException. There is a class AssertionError, and since it is located inside java.lang package, it is imported automatically. Clojure pre/post conditions throw it, so just use AssertionError instead of AssertionException, and your code should run fine.

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

Sidebar

Related Questions

How do you write first responder unit tests? I'm trying to write a test
I am trying to write my first unit test for one of my service
I'm currently trying to write some unit test on some javascript files. My first
Any ideas on this one? I'm trying to write a unit test that will
I'm trying to write a unit test that will loop through all action methods
i'm trying to write an unit test for my Android's RelativeLayout. Currently, my testcode
I am trying to write a unit test for my one controller to verify
I'm trying to write a unit test that will raise an event on a
I'm trying to write a unit test for a piece of code that generates
I am trying to write a unit test for a client server application. To

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.