hspec-junit-formatter: A JUnit XML runner/formatter for hspec

[ library, mit, testing ] [ Propose Tags ] [ Report a vulnerability ]

Allows hspec tests to write JUnit XML output for parsing in various tools.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 1.0.0.0, 1.0.0.1, 1.0.0.2, 1.0.0.4, 1.0.0.5, 1.0.1.0, 1.0.2.0, 1.0.2.1, 1.0.2.2, 1.0.3.0, 1.1.0.0, 1.1.0.1, 1.1.0.2, 1.1.1.0, 1.1.2.0, 1.1.2.1
Change log CHANGELOG.md
Dependencies array (>=0.5.2.0), base (>=4.11.1.0 && <5), conduit (>=1.3.1), containers (>=0.5.11.0), directory (>=1.3.1.5), exceptions (>=0.10.0), filepath (>=1.4.2), hspec-api (>=2.10.0), hspec-core (>=2.10.0), iso8601-time (>=0.1.5), regex-base (>=0.94.0.2), regex-tdfa (>=1.3.2.2), text (>=1.2.3.1), time (>=1.8.0.2), xml-conduit (>=1.8.0.1), xml-types (>=0.3.6) [details]
License MIT
Copyright 2021 Renaissance Learning Inc
Author Freckle R&D
Maintainer engineering@freckle.com
Category Testing
Home page https://github.com/freckle/hspec-junit-formatter#readme
Bug tracker https://github.com/freckle/hspec-junit-formatter/issues
Source repo head: git clone https://github.com/freckle/hspec-junit-formatter
Uploaded by PatrickBrisbin at 2024-07-03T18:05:38Z
Distributions LTSHaskell:1.1.2.1, Stackage:1.1.2.1
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 3211 total (105 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-07-03 [all 1 reports]

Readme for hspec-junit-formatter-1.1.2.1

[back to package description]

hspec-junit-formatter

Hackage Stackage Nightly Stackage LTS CI

A JUnit XML runner/formatter for hspec.

Usage (with hspec-discover)

Place the following in test/SpecHook.hs:

import Test.Hspec
import Test.Hspec.JUnit.Config
import qualified Test.Hspec.JUnit.Formatter as Formatter

hook :: Spec -> Spec
hook = Formatter.use $ defaultJUnitConfig "test-suite"

This replaces the usual formatter, so only a JUnit report is generated and no other output is visible.

Registering instead of using

To make the JUnit formatter available for use with --format, but not used by default, use register:

hook2 :: Spec -> Spec
hook2 = Formatter.register $ defaultJUnitConfig "test-suite"

Adding a JUnit report

To produce a JUnit report in addition to normal output, use add:

hook3 :: Spec -> Spec
hook3 = Formatter.add $ defaultJUnitConfig "test-suite"

Environment Configuration

To configure things via @JUNIT_@-prefixed environment variables, import Formatter.Env instead. It exports all the same functions:

import qualified Test.Hspec.JUnit.Formatter.Env as FormatterEnv

And set the necessary variables,

JUNIT_OUTPUT_DIRECTORY=/tmp
JUNIT_SUITE_NAME=my-tests
hook4 :: Spec -> Spec
hook4 = FormatterEnv.add

Environment Enabling

To only apply a hook if JUNIT_ENABLED=1, wrap it in whenEnabled:

JUNIT_ENABLED=1
hook5 :: Spec -> Spec
hook5 = FormatterEnv.whenEnabled FormatterEnv.add

Without hspec-discover

Hooks are just functions of type Spec -> Spec, so you can apply them right before calling hspec in main:

main :: IO ()
main = hspec $ FormatterEnv.whenEnabled FormatterEnv.add spec

spec :: Spec
spec = describe "Addition" $ do
  it "adds" $ do
    2 + 2 `shouldBe` (4 :: Int)

Golden Testing

This project's test suite uses [hspec-golden][] to generate an XML report for Example.hs and then compare that with golden XML files checked into the repository. If your work changes things in a functionally-correct way, but that diverges from the golden XML files, you need to regenerate them.

  1. Run rm tests/golden*.xml
  2. Run the specs again

We maintain specific golden XML files for GHC 8.x vs 9.x, so you will need to re-run the test suite with at least one of each series to regenerate all the necessary files.


LICENSE