Home > Net >  Split nunit tests in miltiple threads
Split nunit tests in miltiple threads

Time:03-12

I test a shop website. I have tests for one user. The tests are sequential and take a long time. The problem is that when tests for same user are run in parallel, they can interfere with each other (for example, in one test, the item was added to the cart, and in the other it was removed). I want to add a second user and run the tests in parallel. So I need to somehow specify that tests for different users are executed in different threads. Unfortunately, the attribute [Parallelizable] does not provide such an opportunity. Is there some way to explicitly specify which tests should be run in each of the threads?

CodePudding user response:

Create UserProvider. In that class, you should create a collection with users. And you need two methods:

1 - get and delete the user from the collection.

2 - back user to collection

All methods should be wrapped with lock.

Rework test methods like:

// get a user from UserProvider.
try
{
  // test method code
}
finally
{
  // return user to UserProvider
}
  • Related