junit-xml-0.1.0.0: Producing JUnit-style XML test reports.

Safe HaskellNone
LanguageHaskell2010

Text.XML.JUnit

Contents

Description

A module for producing JUnit style XML reports, for consumption by CI platforms like Jenkins. Please see the README at https://github.com/jwoudenberg/junit-xml.

Synopsis

Writing test reports

writeXmlReport :: FilePath -> [TestSuite] -> IO () Source #

This function writes an xml report to the provided path.

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ passed "A passing test"
          & inSuite "Test suite"
      , failed "A failing test"
          & inSuite "Test suite"
      ]

Test report constructors

passed :: Text -> TestReport Passed Source #

Create a report for a passing test.

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ passed "A passing test"
          & stdout "Test ran succesfully!"
          & stderr "Warning: don't overcook the vegetables!"
          & time 0.003
          & inSuite "Test suite"
      ]

skipped :: Text -> TestReport Skipped Source #

Create a report for a skipped test.

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ skipped "A skipped test"
          & inSuite "Test suite"
      ]

failed :: Text -> TestReport Failed Source #

Create a report for a failed test.

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ failed "A failing test"
          & stdout "Running test..."
          & stderr "Test failed: expected 3 slices of pizza but got one."
          & failureMessage "Not enough pizza"
          & failureStackTrace [Pizza, Pizzeria, Italy]
          & time 0.08
          & inSuite "Test suite"
      ]

errored :: Text -> TestReport Errored Source #

Create a report for a test that threw an error.

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ errored "A test that threw an error"
          & stdout "Running test..."
          & stderr "Unexpected exception: BedTime"
          & errorMessage "Operation canceled due to BedTimeOut"
          & errorStackTrace [Bed, Sleep, Night]
          & time 0.08
          & inSuite "Test suite"
      ]

inSuite :: Text -> TestReport outcome -> TestSuite Source #

Wrap a test report in a suite, allowing it to be added to the list of reports passed to writeXmlReports.

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ passed "Passed test"
          & inSuite "Some test suite"
      ]

Adding test report details

stdout :: Text -> TestReport outcome -> TestReport outcome Source #

Add the stdout produced running a test to the report for that test.

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ passed "A passing test"
          & stdout "Test ran succesfully!"
          & inSuite "Test suite"
      ]

stderr :: Text -> TestReport outcome -> TestReport outcome Source #

Add the stderr produced running a test to the report for that test.

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ failed "A failing test"
          & stderr "Expected 4, but got 2."
          & inSuite "Test suite"
      ]

time :: Double -> TestReport outcome -> TestReport outcome Source #

Add the running time of a test to the report for that test.

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ passed "A passing test"
          & time 0.003
          & inSuite "Test suite"
      ]

failureMessage :: Text -> TestReport Failed -> TestReport Failed Source #

Add an error message to the report of a failed test.

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ failed "A failing test"
          & failureMessage "Laundromat exceeds noise tolerance."
          & inSuite "Test suite"
      ]

failureStackTrace :: [Text] -> TestReport Failed -> TestReport Failed Source #

Add a stack trace to the report of a failed test.

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ failed "A failing test"
          & failureStackTrace [AnkleClass, LegClass, LimbClass]
          & inSuite "Test suite"
      ]

errorMessage :: Text -> TestReport Errored -> TestReport Errored Source #

Add an error message to the report for a test that threw an exception.

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ errored "A test that threw an error"
          & errorMessage TooMuchNetflixException
          & inSuite "Test suite"
      ]

errorStackTrace :: [Text] -> TestReport Errored -> TestReport Errored Source #

Add a stack trace to a report for a test that threw an exception

    import Data.Function ((&))

    writeXmlReport "report.xml"
      [ errored "A test that threw an error"
          & errorStackTrace ["at closeCurtain line 3", "at goToSleep line 8"]
          & inSuite "Test suite"
      ]

Helper types

data TestReport outcome Source #

The report for a single test case.

data TestSuite Source #

A test report annotated with the test suite it is part of.