Run tests by tasks

Just starting the clojure track and noticed that the tests are tagged with metadata for the task.

I was trying to figure out how to run just the test for a task.

I tried all sort of combinations of: clj -X:test :includes but nothing worked.

I found this GitHub issues Run tests by tasks · Issue #783 · exercism/clojure · GitHub

Applying the :test-selector allowed me to run lein test :task 1

Just wondering if it’s possible to do the same with clj -X:test

I can’t comment on the question asked but do note that most the exercises do not have task metadata; the task metadata is only found on “concept” exercises. Lesson in the syllabus is associated with a concept exercise. All the other exercises are practice exercises. There are 10 concept exercises and 95 practice exercises on the Clojure track.

1 Like

I don’t know if there’s a straightforward solution that allows filtering by task the way lein does. If the metadata could work as a flag, for example, ^:task1 instead of a map like ^{:task 1}, then running tests by task would be trivial: clj -X:test :includes '[:task1]' would run all tests with the ^:task1 metadata. This is probably the easiest approach for now.

Edit: Another approach would be to add metadata, so ^{:task 1} would become ^{:task 1 :task1 true} and clj -X:test :includes '[:task1]' should still work. This approach doesn’t break the existing setup.

1 Like

I’ve updated the relevant exercises, 25 in total. The selectors for each exercise are listed in their project.clj file and look like this:

:test-selectors {:task-1 :task-1
                 :task-2 :task-2
                 :production-rate :production-rate
                 :working-items :working-items}

Running all tests related to task-1 :

lein test :task-1

or

clj -X:test :includes '[:task-1]'

Running all tests related to task-1 and task-2 :

lein test :task-1 :task-2

or

clj -X:test :includes '[:task-1 :task-2]'

It’s also possible to run tests by function name.

Running all tests related to the production-rate function :

lein test :production-rate

or

clj -X:test '[:production-rate]'

Running all tests related to the production-rate and working-items functions :

lein test :production-rate :working-items

or

clj -X:test '[:production-rate :working-items]'
2 Likes

Will this be documented in Testing on the Clojure track | Exercism's Docs ?

Of course! I’m already working on updated and expanded documentation that will include more details. I’ve already added three more articles, for a total of nine. There will be many many changes, including this one :slight_smile:

2 Likes