diff --git a/docs/en/Community-Articles/2025-09-17-Integration-Testing-Best-Practices-for-Building-a-Robust-Application-Layer/article.md b/docs/en/Community-Articles/2025-09-17-Integration-Testing-Best-Practices-for-Building-a-Robust-Application-Layer/article.md index 88057dc372..f5e02c6ff3 100644 --- a/docs/en/Community-Articles/2025-09-17-Integration-Testing-Best-Practices-for-Building-a-Robust-Application-Layer/article.md +++ b/docs/en/Community-Articles/2025-09-17-Integration-Testing-Best-Practices-for-Building-a-Robust-Application-Layer/article.md @@ -1,4 +1,4 @@ -# Integration Testing Practices for a Strong Application Layer +# Integration Testing Best Practices for Building a Robust Application Layer ## 1. Introduction to Integration Testing @@ -8,10 +8,10 @@ Whereas unit tests verify individual parts one by one, **integration tests confi **Why Integration Testing Is Important:** -* **๐Ÿ”’ Reliability:** Checks the system works as it should, even with network problems, service stops, or incorrect data. -* **๐Ÿ”ง Easy to Update:** Makes sure adding or changing parts doesn't break what already works. -* **๐Ÿ’Ž Good Quality:** Finds problems before users do. -* **๐Ÿ— Strong Application Layer:** Checks that database actions, service handling, and API communications all work together correctly. +* **Reliability:** Checks the system works as it should, even with network problems, service stops, or incorrect data. +* **Easy to Update:** Makes sure adding or changing parts doesn't break what already works. +* **Good Quality:** Finds problems before users do. +* **Strong Application Layer:** Checks that database actions, service handling, and API communications all work together correctly. **Example: Detailed Integration Test with Dependency Injection** @@ -37,7 +37,7 @@ public async Task OrderCreation_WithValidInput_ShouldPersistAndReturnSuccess() This example uses a memory `TestServer` to act like the full HTTP process, from the controller to the database, for a more real test. -## 2. ๐Ÿงช Setting Up a Separate Test Area +## 2. Setting Up an Isolated Integration Test Environment Integration tests should happen in their own area to prevent: @@ -75,7 +75,7 @@ public async Task OrderCreation_RollsBack_AfterTest() Using actions makes sure tests stay separate and can run at the same time safely. -## 3. ๐ŸŒฑ Starting Data for Predictable Integration Tests +## 3. Seeding Test Data for Consistent Integration Results Start data gives a steady base for tests. Include complex links for real situations. @@ -96,7 +96,7 @@ private static async Task SeedData(AppDbContext dbContext) **Tip:** Use the Builder style or a special `TestSeeder` class to make detailed, reusable data setups. -## 4. ๐Ÿ”„ Testing How APIs and Services Work Together +## 4. Validating API and Service Layer Interactions Integration tests should copy what real users do to check the whole request-response process. @@ -119,7 +119,7 @@ await Assert.ThrowsAsync(async () => Test both normal uses and unusual ones like timeouts, bad requests, and too many users at once for a truly reliable API. -## 5. ๐Ÿ›  Mimicking Outside Parts +## 5. Mocking External Dependencies in Integration Tests Use copies or fake versions for services like payment systems, emails, or other APIs to keep your application logic separate. @@ -140,7 +140,7 @@ Assert.Contains("Payment service unavailable", await response.Content.ReadAsStri Mimicking lets you act like things are failing (like APIs timing out or services being down) and check that your application handles these issues well without using real network calls. -## 6. โœ… Testing Both Good and Bad Situations +## 6. Covering Success and Failure Scenarios in Tests A good test set has full coverage of both successful actions and error handling. @@ -163,7 +163,7 @@ Assert.Equal(HttpStatusCode.Conflict, stockResponse.StatusCode); Testing everything makes sure your application layer gives helpful and correct error messages to users. -## 7. ๐Ÿงน Cleaning Up and Keeping Tests Separate +## 7. Ensuring Cleanup and Test Isolation Keep test results steady by making sure each test is totally separate from others. @@ -190,7 +190,7 @@ public class OrderTests : IDisposable Clean up automatically for tests that run at the same time using `IDisposable` or by putting each test in a database action. -## 8. ๐Ÿค– Automating and Adding to CI/CD +## 8. Automating Integration Tests with CI/CD Pipelines Automate tests in CI/CD lines for regular, consistent checking. @@ -212,7 +212,7 @@ jobs: Regular testing finds integration problems early, saving effort over time. -## 9. ๐Ÿช Complete Integration Test Example with a Basic Comparison +## 9. Complete Integration Test Example with a Basic Comparison ```csharp [Fact] @@ -237,7 +237,7 @@ public async Task CompleteOrderWorkflow_ShouldPersistAllSteps() } ``` -๐Ÿช **Cookie Comparison:** +๐Ÿช **Cookie Comparison** * **Starting products** are like the dough you have ready. * **The new order** is like the new stuff you mix in. @@ -248,10 +248,10 @@ This shows how a good application layer uses new and old data well together. --- -### 10. Conclusion +### 10. Summary: -* โœ… **๐Ÿงช Separate Area:** Ensures tests run on their own. -* โœ… **๐ŸŒฑ Start Data:** Gives results that are consistent. -* โœ… **๐Ÿ›  Mimicking Outside Parts:** Keeps tests stable. -* โœ… **โœ… Testing Both Good and Bad:** Makes the situation solid. -* โœ… **๐Ÿค– CI/CD Automation:** Keeps the system stable. +* **Separate Area:** Ensures tests run on their own. +* **Start Data:** Gives results that are consistent. +* **Mimicking Outside Parts:** Keeps tests stable. +* **Testing Both Good and Bad:** Makes the situation solid. +* **CI/CD Automation:** Keeps the system stable.