Skip to content

Commit fcc428e

Browse files
nickAP02nicole.apaflo
andauthored
Added some sections to the Unit testing chapter (#205)
Co-authored-by: nicole.apaflo <nicole.apaflo@CERGITECH64-PC>
1 parent 6864cd7 commit fcc428e

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

en/miscellaneous/testing.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,35 @@ description: In this chapter, we will delve into the critical aspects of testing
55
---
66

77
## Unit Testing
8-
Unit testing is a fundamental practice in web development. It involves testing individual components or functions to ensure they work as expected. This practice can catch bugs early, improve code quality, and make refactoring safer Unit testing is essential for the following reasons:
8+
Unit testing is a fundamental practice in web development. It involves testing individual components or functions to ensure they work as expected. This practice is included in a software development approach called test-driven development(TDD) which consists in writing unit tests out of the software requirements first then write code after.Let's now see why we should write Unit tests.
99

10-
- It verifies that individual parts of your codebase are working correctly.
10+
## Why write Unit Tests?
11+
Unit testing is widely used because of the following reasons :
12+
- In TDD,the software requirements are turned into specific test cases. The software is then improved to pass the new tests.
13+
- In other to verify that individual parts of the codebase is working correctly.
14+
- It allows code modification without affecting the functionality of other units or the software
1115
- It provides a safety net when refactoring or making changes.
1216
- It helps document the expected behavior of functions and components.
17+
- It helps to no repetition of modules because each module has it own responsibility
18+
19+
## Benefits of Unit Tests
20+
The main advantage of unit tests is their laser-sharp focus. Since they test a single function, they give precise feedback. If a unit test fails, in most cases, you can be sure that the specific function being tested is the problem.
21+
- Unit tests help to find and fix bugs quickly and easily.
22+
- Unit tests contribute to higher code quality.
23+
- Unit tests contribute to better application architecture.
24+
- Unit tests act as documentation.
25+
26+
## Best Practices for creating Unit Tests
27+
To ensure that you have good Unit tests follow this best practices :
28+
- Write tests during development, not after
29+
- Test cases should not duplicate the implementation logic.
30+
- Test cases should exhibit the same behavior as long as their code is unchanged.
31+
- Use a consistent naming convention for the test cases
32+
- Avoid using conditional logic expressions in Unit tests
33+
- If possible automate Unit tests
1334

1435
## Testing Frameworks
15-
Testing frameworks streamline the process of writing and running tests. Two popular frameworks are Jest and Mocha.
36+
Testing frameworks streamline the process of writing and running tests. Two popular frameworks in JavaScript are Jest and Mocha.
1637

1738
## Jest
1839
Jest is a zero-config, all-in-one popular testing framework. It's suitable for both unit and integration testing. Let's see how to get started with Jest.

0 commit comments

Comments
 (0)