Clojure

Provide a clojure.test function to run a single test case with fixtures

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Release 1.6
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

clojure.test test cases are functions and can be invoked directly. However, in the case that the test relies on fixtures, this does not work. It should be possible to run a single test case with all fixtures applied.

Approach: Add new test-vars that takes a collection of vars to run.

Patch: code: clj-866-test-vars.patch, test: CLJ-866-test.patch

Screened by: Alex Miller

  1. CLJ-866-test.patch
    03/Aug/13 3:35 PM
    2 kB
    Gary Fredericks
  2. clj-866-test-vars.patch
    22/Oct/12 6:09 PM
    2 kB
    Anthony Grimes

Activity

Hide
Anthony Grimes added a comment -

I just added clj-866-test-vars.patch (22/Oct/12 6:09PM).

I had to implement this hackishly in Leiningen a few days ago, so I'm very excited to get this functionality in clojure.test itself.

This patch adds a test-vars function that solves this problem (and is more general). You can test as many vars as you want with it, with fixtures. It works by grouping vars passed by their namespace and then running them all with appropriate fixtures applied. Being able to run a single test isn't the problem here, being able to run only specific tests is. If we wrote a function to run one test with fixtures but we actually needed to run several, just not all tests, we'd end up having to run once-fixtures more than once which is wasteful. I think test-vars is a good solution that solves both this problem and the one I just mentioned.

Show
Anthony Grimes added a comment - I just added clj-866-test-vars.patch (22/Oct/12 6:09PM). I had to implement this hackishly in Leiningen a few days ago, so I'm very excited to get this functionality in clojure.test itself. This patch adds a test-vars function that solves this problem (and is more general). You can test as many vars as you want with it, with fixtures. It works by grouping vars passed by their namespace and then running them all with appropriate fixtures applied. Being able to run a single test isn't the problem here, being able to run only specific tests is. If we wrote a function to run one test with fixtures but we actually needed to run several, just not all tests, we'd end up having to run once-fixtures more than once which is wasteful. I think test-vars is a good solution that solves both this problem and the one I just mentioned.
Hide
Alex Miller added a comment -

This is highly useful. Could you add a test to the patch?

Show
Alex Miller added a comment - This is highly useful. Could you add a test to the patch?
Hide
Gary Fredericks added a comment -

Attached patch with a test, which should apply cleanly on top of Anthony's.

Also made sure a mostly-equivalent version (that used test-var) was failing without the new function.

Show
Gary Fredericks added a comment - Attached patch with a test, which should apply cleanly on top of Anthony's. Also made sure a mostly-equivalent version (that used test-var) was failing without the new function.
Hide
Alex Miller added a comment -

New version of the patch incorporating feedback has been attached, switching to Vetted so someone can take a look again.

Show
Alex Miller added a comment - New version of the patch incorporating feedback has been attached, switching to Vetted so someone can take a look again.

People

Vote (11)
Watch (8)

Dates

  • Created:
    Updated:
    Resolved: