mkirk mkirk - 2 months ago 20
R Question

stubs and mocks in R

I've spent lots of time with RSpec and some time with xunit style tests. I've gotten accustom to having mocks and stubbing at my disposal.

Is there anything like mocks or stubbing in R? What frameworks have them?

If not how do you isolate your tests?

Answer

It wasn't available until 4 years after you asked this question, but it looks like testthat does include a with_mock() function now:

https://github.com/hadley/testthat/blob/master/R/mock.R

Seems to fit the bill pretty well.