C# Stress Test - Simulate multiple access to a given shared resource
问题 How can you simulate/stress test about 100 users accessing a given shared resource (e.g. Database) in a c# unit test? 回答1: Assuming you're accessing real DB you're in the scope of integration tests. The simplest way is to access the resource from multiple threads. For example: [Test] public void SimpleStressTest() { bool wasExceptionThrown = false; var threads = new Thread[100]; for(int i = 0; i < 100; i++) { threads[i] = new Thread(new ThreadStart((Action)(() => { try { AccessDB(); } catch