Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 4, 2020 09:32 pm GMT

Introduction to TDD: What it is and why it is important

Many companies today are using test driven development or TDD to create their web software.

Why is test driven development so popular?

It prevents issues and bugs in the future, it can increase the efficiency of your work flow, and help teams communicate the intentions of their code's functionality. A downside of TDD is that it takes longer to get a project started, so it required a little bit of up-front patience.

The basic flow of TDD:

  1. Create a test (make sure it fails so you don't get a false positive)
  2. Write code to try to pass the test
  3. Once passing, create the next test and repeat

Listed below are some concepts to keep in mind while creating tests:

Readable -> Make it clear what the test's actual and expected behavior is, and why.

Isolated -> Make sure tests only cover a particular segment of code, because you don't want certain tests interfering with other tests. If interference occurs, you may not know if the test failed due to your target code or from a previous test.

Thorough -> Prepare for edge cases, like if someone enters in something totally unrelated to the expected input. For example, what if someone tries to submit an empty form?

Explicit -> This ties in with code readability. If someone looks at the test, they should be able to require little setup.

There are several main types of tests:

Unit test -> small pieces of functionality

Integration test -> checking if all the smaller tests/code work together such as seeing if the app communicates with an API (Application programming interface) correctly

End-to-End -> tests entire application from user viewpoint (examples: Selenium or Cypress.io)

What you need to get started (usually in the form of libraries):

  1. Testing environment/test runner (the place to run tests)
  2. Testing framework (Ex. Mocha or Jasmine, organizes/holds your test code)
  3. An assertion library (this allows you to not have to write tons of if-statements, this does the actual verifications of test results)

Sources:
https://www.linkedin.com/learning/javascript-test-driven-development-es6

https://stackoverflow.com/questions/25678063/whats-the-difference-between-assertion-library-testing-framework-and-testing-e


Original Link: https://dev.to/wolfdominion/introduction-to-tdd-what-it-is-and-why-it-is-important-2hhf

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To