DEV Community

Sm0ke
Sm0ke

Posted on

Automated tests - BDD for your Express backend

I love BDD. It made my life as a developer 1000x better. Just because I can fix and create tests way before the product reaches QA time. Here are three of the most common types of automated tests:

  • Unit tests: A single piece of code (usually an object or a function) is tested, isolated from other pieces
  • Integration tests: Multiple sections are examined together, for example, testing database access code against a test database
  • Acceptance tests: (also called Functional tests): Automatic testing of the entire application, for example using a tool like Selenium to run a browser automatically.

BDD is TDD on steroids

Let's see first how you can do TDD - Test Driven Development; you need to change the way you develop. Here are the steps you start coding a feature:

  • Start by writing a test
  • Run the test and any other tests. At this point, your newly added test should - fail. If it doesn’t fail here, it might not be testing the right thing and thus has a bug in it.
  • Here you start working at the feature: write the minimum amount of code required to make the test pass.
  • Run the tests to check the new test passes
  • Optionally refactor your code
  • Go back to the first step

It can take some effort to learn well, but spending the time can pay off big. TDD projects often get a code-coverage of 90-100%.

Read the full article on my blog. Thank you!

Code less. Live more!

Top comments (0)