DEV Community 👩‍💻👨‍💻

Cesar Codes
Cesar Codes

Posted on

Quick fix for "Mapper already initialized" error in AutoMapper/xUnit tests

xUnit and Automapper error

My team has experienced a couple of instances where some of our developer machines will hit the following error while executing multiple xUnit tests that use AutoMapper:

Mapper already initialized. You must call Initialize once per application domain/process

If you Google around, there are a few suggested solutions, but they didn't seem to work for us. So after some research, I checked out the docs and realized for our needs we could just turn off xUnit parallelization. I think for most people this should be fine unless you're running huge numbers of tests that take a long time. 
In order to do so, you can simply set the following line on your main test file or test configuration file as such (line #5):

That should be a quick fix to the problem. Continue dotnet coring in the free world, y'all!

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.