GithubHelp home page GithubHelp logo

fixa's Introduction

fixa

Better fixtures for Clojure

Why does clojure.test limit us to a single set of :each and :once fixtures for all tests in a namespace?

Shouldn't we have the granularity of being able to apply particular fixtures to an individual test?

fixa lets you define fixtures at the individual test level using a simple metadata notation.

Clojars Project

Usage

Firstly you need to add the fixa metadata to your test vars, then choose the appropriate instructions for your test runner (kaocha or clojure.test).

Note that the fixa fixtures will run after any fixtures defined by use-fixtures.

Annotate your tests

Add :fixa/fixture (singular) or :fixa/fixtures (a list) as metadata to your deftest:

(deftest ^{:fixa/fixture fixture-a} single-fixture-test
  (is (= 1 1)))

(deftest ^{:fixa/fixtures [fixture-a fixture-b]} multiple-fixtures-test
  (is (= 1 1)))

Kaocha

All that's needed is the fixa.kaocha/wrap-run plugin. Add it to your tests.edn like this:

#kaocha/v1 {:plugins [:hooks]
            :kaocha.hooks/wrap-run [fixa.kaocha/wrap-run]}

clojure.test

Unfortunately due to the way clojure.test is written, an alternative deftest is required to smuggle the fixtures through.

(require '[fixa.clj-test :refer [deftest]])

(deftest ^{:fixa/fixture fixture-a} single-fixture-test
  (is (= 1 1)))

Built-in fixtures

Now that fixa has added the ability to have per-test fixtures, we can do more. The following are built-in fixtures provided by the library.

fail-after

You can add a :fixa/fail-after to your tests which will make the test start to fail when the date is surpassed:

(deftest ^{:fixa/fail-after "2023-01-05"} christmas-decorations-test
  (is (christmas-decorations)))

run-after

You can add a :fixa/run-after to your tests which will make the test skip evaluation until the date is surpassed:

(deftest ^{:fixa/run-after "2022-12-01"} future-v2-integration-test
  (is (some-feature-only-available-in-v2)))

Development

CircleCI

fixa's People

Contributors

oliyh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fixa's Issues

Timebomb meta

Maybe call it something else, but will make a test fail after a certain date

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.