racket-mock icon indicating copy to clipboard operation
racket-mock copied to clipboard

Make it easier to write test cases that reset mocks

Open jackfirth opened this issue 9 years ago • 1 comments

Often a function tested with mocks may have multiple behaviors that need to be tested and which require mocks be set up in different ways. mock-reset! and with-mock-behavior provide building blocks for doing this, but it can be clunky as every test case needs to remember to reset mocks at the end to ensure it doesn't affect other test cases. A handful of forms that create RackUnit test cases which automatically reset all mocks in a function at the end of the test would be very useful.

jackfirth avatar Jul 10 '16 23:07 jackfirth

with-mocks helps with this significantly, but it's still wordy to 1) construct a test case, 2) bring mocks into scope with with-mocks, and 3) change mock behaviors. A form for doing all three of these would be nice. Idea:

(test-case/mocks "Some test"
  #:mocks some-proc
  #:behavior some-mocked-proc other-behavior
  test ...)

This syntax generalizes to test-equal?/mock and the various other test case sugar forms.

jackfirth avatar Jul 26 '16 04:07 jackfirth