Although Haskell's type system by itself gives you a lot of reassurance that you're writing correct code, good unit tests can help you maintain and understand your code even better.
- [Instructor] In this video, we're going to look at…unit testing the grid using HSpec.…We'll start off by doing a small clean-up,…refactoring data out of our model,…and then we'll start to test our functions using HSpec.…So let's have a look at the test file.…So in the first video, in the section,…we imported Test.Hspec and wrote a very simple test…simply to show how to write a test.…And now we can actually look at testing…some of the functions that we've written.…
But first of all, it occurs to me that…this library, lib, contains various functions…that actually transform and display a grid.…But it also contains these two items of data:…a list of languages and a grid.…And this might now be a good time to actually look…at extracting those into a separate place.…In the future, we might read those…from a file, for example.…So let's create a new library called data.hs.…
We can remove these functions from here…and paste them into this new library.…So of course we need to declare this as data…and we can export grid and languages.…
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Discovering Haskell with GHCI
- Haskell datatypes and functions
- Using higher order functions for data manipulation and code reuse
- Editing Haskell source code
- Creating a project with Stack
- Writing and conducting tests