user4779
user4779

Reputation: 817

NUnit - Unit testing two separate tests in parallel

I understand NUnit runs tests in parallel, which isn't what this question is about exactly. In a single test, I can have two local socket connections open using TcpClient on different ports, which can communicate with one another in the same unit test. The problem is the address space is of course shared by the thread executing the unit test, so it doesn't simulate communication through a network how I want.

If I have a test called Test1 with one TcpClient, and whilst it's running, I run Test2 with the other TcpClient, in these two tests I can have both the unit tests talking to one another and communicating - testing the protocol I've designed with separate address spaces, which does give me the simulation of a network I desire, and allows me to do the proper test assertions.

Now the question is, is there any way to do this automatically? I'd like to have a single test that can run Test1 & Test2, where both these tests communicate via their respective sockets, instead of starting them both up manually in parallel.

Upvotes: 3

Views: 561

Answers (2)

Ankit Jasuja
Ankit Jasuja

Reputation: 15

I do not think that is possible.you can decide which test should run after another, so basically order. but usually, tests are not required to be run in parallel.

Upvotes: 0

PMF
PMF

Reputation: 17185

NUnit is not designed to run tests in different processes (nor is any other unit testing framework I'm aware of). It's designed to start as many tests as possible in the same process, to increase performance (creating processes is expensive).

Of course, that doesn't mean it's impossible to do this, but it's not a domain of NUnit itself. The question doesn't give much information about how the tests are structure, but I'm assuming there's a test assembly for the server and another test assembly for the client. Only when they run at the same time, the tests work.

I would go ahead and create a third test assembly that just starts the other two, really creating processes manually, e.g. launching

dotnet test ServerUnitTests.dll
dotnet test ClientUnitTests.dll

["Integration Tests" would be the better term here, but that's a detail]

Upvotes: 3

Related Questions