Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
33 lines (23 sloc) 1.46 KB

racket-mock Build Status codecov Stories in Ready

Mocks for Racket testing.

raco pkg install mock
raco pkg install mock-rackunit # RackUnit integration

Documentation: mock, mock-rackunit

This library defines mocks, which are "fake" implementations of functions that record calls made to them. Two separate packages are provided, the main package mock and the RackUnit checks package mock-rackunit. In standard uses, the mock-rackunit dependency is needed only for test code. For a thorough introduction, see The Mock Guide. For a full API reference, see The Mock Reference.


(require mock mock/rackunit)

(define/mock (foo)
  ; in test, don't call the real bar
  #:mock bar #:as bar-mock #:with-behavior (const "wow!")

(define (bar) "bam!")

(foo) ; "bam!"

(with-mocks foo
  (foo) ; "wow!"
  (check-mock-num-calls 1 bar-mock))
You can’t perform that action at this time.