Unit Testing Techniques
퇽회 Definition
Unit testing is a software testing method where individual components (units) of code are tested independently to ensure they work correctly.
퇽훹 Common Unit Testing Techniques
1. Black Box Testing
- Tests functionality without knowing internal code
- Focuses on inputs and expected outputs
퇽혉 Example: Checking if a login function works with valid/invalid credentials
2. White Box Testing
- Tests Covers paths, conditions, and loops
퇽혉 Example: Testing all branches in a function
3. Grey Box Testing
- Combination of black box and white box
- Tester has partial knowledge of internal code
4. Boundary Value Analysis (BVA)
- Tests values at the edges of input range
퇽혉 Example: Age input ᭒ test 17, 18, 19
5. Equivalence Partitioning
- Divides inputs into groups (valid/invalid)
- Tests one value from each group
6. Decision Table Testing
- Uses a table to test different combinations of inputs
7. State Transition Testing
- Tests system behavior based on state changes
8. Error Guessing
- Based on tester experience to predict errors
9. Mocking and Stubbing
- Replace real components with dummy objects
- Useful when external systems are involved
10. Test-Driven Development (TDD)
- Write test cases before writing code
- Follow cycle: Test ᭒ Code ᭒ Refactor
퇽훹 Tools for Unit Testing
- JUnit
- TestNG
- Mockito
퇽훹 Importance
- Detects bugs early
- Improves code quality
- Simplifies debugging
- Supports continuous integration
- Enhances maintainability
