0

I have a solution written on c#, .netcore 2.2 and the testing framework is xunit that looks pretty much like this:

-src

  --controllers

  --services

-test

  --controllers.integrationtest

  --services.integratiotest

we are performing some integration test with two distinct dlls (controllers.integrationtest.dll & services.integrationtest) that use the same database (solutionname.test)

now, when I run "dotnet test" on the solution, it seems that the two dlls are trying to access the same resource (database) and one dll gets a deadlock.

The thing is that I want to disable the parallel execution of the dlls when I run "dotnet test" to avoid that deadlock, so I search that up and the documentation says that to disable parallel execution of dlls you have to:

  1. Add a xunit.runner.json in the root of the csproject which I did and works fine. (this is working on visual studio because I tested it with another feature that deletes the "_" character of test names: [methodDisplay])

  2. Configure xunit.runner.json file to copy always or preserve newest in visual studio so that gets copied on bin folder (as any appsetings.json file)

I've read that you can place an assembly attribute in the assemblyInfo.cs file that by the way it seems that was replaced by the plain csproj so I'm a bit confused.

The ultimate goal that I want to achieve is that when devops use dotnet test the integration test doesn't blow up on concurrency problems.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Rod Ramírez
  • 1,138
  • 11
  • 22
  • Did you try to read the existing question? [Execute unit tests serially (rather than in parallel)](https://stackoverflow.com/questions/1408175/execute-unit-tests-serially-rather-than-in-parallel) adding this line `[assembly: CollectionBehavior(DisableTestParallelization = true)]` somewhere in your code may solve your problem – Pavel Anikhouski May 15 '20 at 14:04
  • Hi!, unfortunatly no, because this answer aims to configure the test collections parallelisation, and what I want to make sure that one assembly doesnt run on parallel with another. I can have multiple test collections on a same assembly. – Rod Ramírez May 15 '20 at 14:13
  • 1
    it looks that u need to disable test parallelisation that was answerd here: https://stackoverflow.com/questions/1408175/execute-unit-tests-serially-rather-than-in-parallel . Microsoft do the same in roslyn tests: https://github.com/dotnet/roslyn/blob/master/eng/config/xunit.runner.json#L3 – Macko May 17 '20 at 20:36

1 Answers1

5

In xUnit the default value for ParallelizeAssemblies is false so I can only assume that a behavior of dotnet test is causing both to be executed together.

Try and run the tests using dotnet vstest. This requires the DLLS to have been built.

dotnet vstest **/*test.dll
J.D. Cain
  • 639
  • 4
  • 16