I have a function that makes a HTTP call and saves the data to the database, for instance like this:
fetchDataAndSaveToDB :: IO ()
fetchDataAndSaveToDB = do
data <- fetchData
saveDataToDB data
I'd like to write some tests for this function. In order to cover all the cases for different data fetched from the HTTP response, I'd like to stub the fetchData function to return the stubbed data constructed in the test, then I can verify the result by making a DB call and verify the saved data is correct. So stubbing a function would be basically replacing the function with another function that has the same signature.
In other languages like Javascript/Ruby/Golang, there are testing tools support stub function to do so. I wonder how to do it in Haskell.
Aucun commentaire:
Enregistrer un commentaire