Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-*(): mock API to increase code coverage #49

Open
dimfalk opened this issue Nov 5, 2022 · 1 comment
Open

test-*(): mock API to increase code coverage #49

dimfalk opened this issue Nov 5, 2022 · 1 comment
Assignees
Labels
tests Unit testing required

Comments

@dimfalk
Copy link
Owner

dimfalk commented Nov 5, 2022

@dimfalk dimfalk added the tests Unit testing required label Nov 5, 2022
@dimfalk dimfalk self-assigned this Nov 5, 2022
dimfalk added a commit that referenced this issue Nov 11, 2022
dimfalk added a commit that referenced this issue Nov 12, 2022
@dimfalk dimfalk changed the title test-*(): increase code coverage test-*(): mock API to increase code coverage Apr 9, 2024
@dimfalk
Copy link
Owner Author

dimfalk commented Apr 12, 2024

 library(mockery)

# set up the mock
mock_download_file <- mock_function(return_value = TRUE)
mock_download_file(file = "test.txt", url = "http://example.com/test.txt")

# call the function that uses download.file
your_function_to_test()

# check the output
expect_true(mock_download_file.calls$file[1] == "test.txt")
expect_true(mock_download_file.calls$url[1] == "http://example.com/test.txt")
library(mockery)

mocked_response <- list(status = 200, body = "Mocked response")

# set up the mock
mock_api_call <- mockery::mock_function(return_value = mocked_response)

# make the request
response <- mock_api_call()

# check the response
response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Unit testing required
Projects
None yet
Development

No branches or pull requests

1 participant