You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/miscellaneous/testing.md
+24-3Lines changed: 24 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,35 @@ description: In this chapter, we will delve into the critical aspects of testing
5
5
---
6
6
7
7
## 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.
9
9
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
11
15
- It provides a safety net when refactoring or making changes.
12
16
- 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
13
34
14
35
## 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.
16
37
17
38
## Jest
18
39
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