Creating test for "No internet access"

I’m creating a R package that uses internet inside a function.

I create a test (using testthat) that is “Internet connection is available”. But I would like to create another one that is “Internet connection is NOT available”.

I think I need to mock the function, but I have no experience with it.

Repo: GitHub - brunomioto/feowR: Download shapefiles of Freshwater Ecoregions of the World (FEOW)

Function: feowR/R/read_feow.R at 90d821907e837e2618367eefb4b8e6d03c0ccb83 · brunomioto/feowR · GitHub

Test: feowR/tests/testthat/test-read_feow.R at 90d821907e837e2618367eefb4b8e6d03c0ccb83 · brunomioto/feowR · GitHub

1 Like

I have just the blog post for this use case, with general mocking in testthat: Update on mocking for testing R packages - R-hub blog

1 Like

the function that you want to mock maybe has to be defined not inside another function

Thank you! All code is now covered and passing all tests.

3 Likes