Chapter 07: Writing Test Code: Difference between revisions

 
(One intermediate revision by the same user not shown)
Line 52: Line 52:
     /    Unit Tests      \
     /    Unit Tests      \
   /______________________\</pre>
   /______________________\</pre>
'''Unit Tests (70%)''': - Fast execution (&lt; 1 second) - Test individual components in isolation - Use mocking for dependencies - Focus on business logic
'''Unit Tests (70%)''':  
* Fast execution (&lt; 1 second)  
* Test individual components in isolation  
* Use mocking for dependencies - Focus on business logic


'''Integration Tests (20%)''': - Test component interactions - Include database, web layer, or external services - Slower execution but higher confidence - Test real scenarios
'''Integration Tests (20%)''':  
* Test component interactions  
* Include database, web layer, or external services  
* Slower execution but higher confidence  
* Test real scenarios


'''UI/End-to-End Tests (10%)''': - Test complete user journeys - Slowest but most comprehensive - Usually automated browser testing
'''UI/End-to-End Tests (10%)''':  
* Test complete user journeys  
* Slowest but most comprehensive  
* Usually automated browser testing


<span id="testing-philosophy"></span>
<span id="testing-philosophy"></span>
Line 397: Line 407:
=== 7.2.3 When to Use Each Type ===
=== 7.2.3 When to Use Each Type ===


'''Use Unit Tests When:''' - Testing business logic in isolation - Validating edge cases and error conditions - Testing pure functions or methods with clear inputs/outputs - Need fast feedback during development
'''Use Unit Tests When:'''  
* Testing business logic in isolation  
* Validating edge cases and error conditions  
* Testing pure functions or methods with clear inputs/outputs  
* Need fast feedback during development


'''Use Integration Tests When:''' - Testing database interactions - Validating component interactions - Testing configuration and wiring - Verifying end-to-end scenarios
'''Use Integration Tests When:'''  
* Testing database interactions  
* Validating component interactions  
* Testing configuration and wiring  
* Verifying end-to-end scenarios


<span id="test-code-patterns-and-quality"></span>
<span id="test-code-patterns-and-quality"></span>
== 7.3 Test Code Patterns and Quality ==
== 7.3 Test Code Patterns and Quality ==