I have written a plumber API and exposed as a service. Now I want to write down the unit test case for all the API's.
Right now API's are doing the below functionality
- Connecting to the database and getting the data
- Grouping the data
- Using the ggplot to plot the graph with the given data.
I have few issue end up with
- I was not able to mock the database connection.
- How do we call the API function from the testthat? API's doesn't have name to call from testthat function file.
- All the API has request and response object how do we mock that? when I tried look into the request and response object it is printing as environment.
Kindly do the needful.
meztez
2
Thanks @meztez for commenting.
Code base has testing the plumber api endpoint, content, content-type, etc.
I was looking for the DB connection Mock up and query data mocking. I have used the RPostgres package to establish the connection.
Couldn't mock it, Tried with Mockery, Mockery2, Monad and fakeweb. It is not mocking the connectivity.
Either package is not available in CRAN or the functions are not exported.
Looking forward for the help with this.
meztez
4
@hariprasad What would you expect a database connection mock to do?
I'm not sure that I understand? I would replace with some actual query results for test purpose, probably stored in an .rds.
file.
Thanks for replying @meztez . I have took the inspiration from the plumber test case and created it. Thanks for the help.
system
Closed
6
This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.