The Iron Code

triangles

Cucumber testing for my homepage

written on 2022-03-11 22:05

This homepage is using a homegrown transactional database which I call Journal. I did not put it in a crate yet, simply because I feel it's not mature enough yet. Directly from the beginning I wrote unit-tests to keep refactoring easy and the API stable for my consumer (the page backend).

So, running these unit-tests is okay-ish - especially if I worked on them last week. Unfortunately I had to do some HTML and CSS stuff in the meantime. So if one of these tests suddenly failed, I would have to read the code again to check, how the specific test is implemented in detail:

running 8 tests
test journal::tests::test_add ... ok
test journal::tests::test_delete ... ok
test journal::tests::test_empty ... ok
test journal::tests::test_iter ... ok
test journal::tests::test_iter_rev ... ok
test journal::tests::test_query ... ok
test journal::tests::test_update ... ok
test journal::tests::test_save_load ... ok

I also added a few cucumber-tests mainly for getting familiar with the great cucumber-rs. A lot of professional experience in using the squish gui testing tool made me a fan of the gherkin-language so I wanted to try it out in a unit-test / integration-test framework as well. It turns out, that even after my brain was shattered by stylesheets I can easily follow the expected behavior of my journal:

Feature: A local transactional db
  Scenario: Adding an entry results in an entry
   ✔  When adding 'first entry'
   ✔  Then the journal has 1 entries
   ✔  And entry number 0 is 'first entry'
  Scenario: Updating an entry preserves the history
   ✔  Given a new entry 'first entry' is added
   ✔  When updating entry number 0 to 'modified'
   ✔  Then the journal has 1 entries
   ✔  And entry number 0 is 'modified'
   ✔  And the history length for entry 0 is 2
   ✔  And for entry 0 the history record 0 is 'first entry'
[Summary]
1 feature
2 scenarios (2 passed)
9 steps (9 passed)

Also, the code/step reusage is quite nice in even two test-cases. For the future, my take is that gherkin in unit/integration tests can be quite nice.

Tagged:
Programming