mock-rackunit

RackUnit checks for testing with mocks from the mock package


Keywords
mock, rackunit, testing, racket
License
Other

Documentation

racket-mock Build Status Coverage Status Stories in Ready

Mocking library for Racket RackUnit testing.

raco pkg install jack-mock

Documentation: mock

This library allows for easy construction of mocks, which are "fake" implementations of functions that record calls made to them for testing.

Currently unstable, API changes may occur.

Example:

(require mock)
(define/mock (displayln-twice v)
  ([displayln (void-mock)]) ; in the test submodule, calls a mock instead of displayln
  (displayln v)
  (displayln v))
(displayln-twice "sent to real displayln")
(mock? displayln) ; #f
(mock-num-calls displayln) ; error - displayln isn't a mock
(module+ test
  (displayln-twice "sent to mock displayln")
  (mock? displayln) ; #t
  (mock-num-calls displayln)) ; 2