Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 1.14 KB

eunit_tdd_practicum.asciidoc

File metadata and controls

28 lines (20 loc) · 1.14 KB

Let to some TDD together

Note
Redo maybe with webmachine

So far this book has talked a lot about the mechanics of tests, how to create them, how to run them and so on. With this chapter I want to do something different and walk threw an example of how to use tests to Test Driven Development.

To do any form of TDD we need a problem to solve in this case I am going to build a function that will take the output of a http request handler in yaws and apply support for ETags to it.

The logic of this is pretty simple as we have three cases.

1) The user has never visited our page before and does not send a If-None-Match header, then we return the content with an ETag header.

2) The user has visited and sends an If-None-Match that does not match the current data, which results in the same result as #1.

3) The User has visited and the Etag matches in which case we send back {status, 304} to tell the client to use their cached data.

To do this we need two files etag.erl and etag_test.erl. For the sake of this chapter we are going to version them as etag_NN.erl and etag_NN_test.erl with each example getting a new value of NN.