CodexBloom - Programming Q&A Platform

Challenges with Load Testing a .NET API for Scalability Planning Using SpecFlow and NUnit

👀 Views: 34 💬 Answers: 1 📅 Created: 2025-10-08
.net load-testing specflow nunit performance C#

I've tried everything I can think of but I'm working on a personal project and While refactoring our automated tests, I’ve been tasked with ensuring that our .NET API can handle increased load effectively. Currently, we are using SpecFlow for BDD-style tests along with NUnit for our unit tests. We've set up some basic load tests, but I’m not sure how to integrate them seamlessly into our existing test suite. For instance, I want to simulate multiple concurrent users hitting the API endpoints but am stumbling with the right approach. I've tried using a simple loop within a task to send parallel requests like this: ```csharp var tasks = new List<Task>(); for (int i = 0; i < 100; i++) { tasks.Add(Task.Run(async () => await client.GetAsync("/api/data"))); } await Task.WhenAll(tasks); ``` This works to some extent, but I’m not seeing how to collect meaningful metrics on response times and error rates effectively. Would it be better to use a dedicated load testing tool like k6 or Apache JMeter instead? Also, while executing tests, we noticed that our database started to slow down significantly under high load, leading to timeouts. Any insights on how to improve the database’s performance in this scenario, such as connection pooling or optimizing queries? Moreover, we’re using Entity Framework Core 6 for data access. Are there specific configurations or patterns that could enhance performance with high query loads? Any strategies to prevent bottlenecks and ensure smooth operation during peak testing would be valuable. Would love to hear how other teams have approached this!