An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
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:
- Create a test (make sure it fails so you don't get a false positive)
- Write code to try to pass the test
- 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):
- Testing environment/test runner (the place to run tests)
- Testing framework (Ex. Mocha or Jasmine, organizes/holds your test code)
- 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
Original Link: https://dev.to/wolfdominion/introduction-to-tdd-what-it-is-and-why-it-is-important-2hhf
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To