I am trying to write some simple code in haskell where there is a function performs a simple database query. In order to unit test Iam using HUnit but not sure how I can mock the database connection and query response.
1
There are 1 answers
Related Questions in HASKELL
- Typeclass projections as inheritance
- How to generate all possible matrices given a number n in Haskell
- Is there a way to get `cabal` to detect changes to non-Haskell source files?
- How to have fixed options using Option.Applicative in haskell?
- How can I create a thread in Haskell that will restart if it gets killed due to any reason?
- Automatic Jacobian matrix in Haskell
- Haskell writing to named pipe unexpectedly fails with `openFile: does not exist (No such device or address)`
- Why does Enum require to implement toEnum and fromEnum, if that's not enough for types larger than Int?
- Non-exhaustive patterns in function compress
- How to get terms names of GADT in Template Haskell?
- Implementing eval() function with Happy parser generator
- How to count the occurences of every element in a list in Haskell fast?
- In Haskell, what does `Con Int` mean?
- Extract a Maybe from a heterogeneous collection
- Haskell, Stack, importing module shows error "Module not found"
Related Questions in HUNIT
- Using mocks in unit testing in Haskell?
- How do I compare Double values in Hunit?
- Create and run a minimal test suite in Haskell using Hunit only
- Mock Database connections in haskell
- Unit testing of internal functions of a module while avoiding dependencies to test framework and HUnit
- Haskell: Multiple Assertions in Unit Testing?
- Haskell Cabal HUnit
- Tasty HUnit test against Either
- Haskell HUnit Function Testing
- Can't cabal install hunit
- How to unit test smart constructor that throw when construction is impossible?
- Why won't my test file import my datastructure? Haskell
- Is it possible to assert an error case in HUnit?
- HUnit does not allow to compile test cases if `Nothing == Nothing` condition is present in the test
- Pattern for generic unit test of type class instance implementations in Haskell
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Pass the function that performs the database query as a parameter to your code, instead of having it "hardwired". During tests, pass a mock function to the code. In production, pass a function that really performs the database query.
This new function parameter should be at the right level of abstraction. For example, something like
is possibly a bad idea, because it still forces the code under test to be aware that things like
Connections and SQL strings exist. Something like thiswould likely be better, because then you are free to pass functions that don't use db-specific
Connectiontypes at all. They could, for example, be backed by an in-memory reference.Notice that you can build
findClientByIdout ofqueryDbForClientby partial application and mapping the result a little. But this should be the task of some setup code, not of the main code that you want to test.Once you start passing functions in this way for the sake of testability and configurability, some common issues start to appear. For example, what if I have multiple dependencies? Passing them all as positional parameters is a chore. This might lead to passing them together in a record-of-functions, perhaps using
Has-like typeclasses so as not to tie your main code to any particular record.