Applying test-driven development to your database

Click for: original source

Test-driven development (TDD) is a popular software development methodology that aims to reduce defects and improve the ease of maintaining code. In this post, you learn how to apply TDD to write queries and expressions with the Fauna Query Language (FQL). By Ron Callahan.

TDD begins with writing a single failing test. For example, if you are implementing a Split() function that accepts a string and a delimiter and returns an array of strings “split” at each occurrence of the delimiter, you would test that Split(“127.0.0.1”, “.”) is equal to [“127”, “0”, “0”, “1”]. When you first run your test suite, the test fails, because you have not yet implemented the Split() function.

The tutorial reads about:

  • TDD overview
  • Setting up your environment
  • Configuring Jest
  • Testing partial FQL expressions
  • Preparing your test harness
  • Create a single failing test
  • Implementation

To test your knowledge, try implementing tests for the remaining two specifications. Once you have those tests in place and passing, try to refactor the implementation of Split(). Notice how TDD allows you to safely refactor your code without introducing regressions. Interesting!

[Read More]

Tags cloud database cicd tdd nosql