Reputation: 89
I'm trying to use NSubstitute in my Unity project (Unity version 2019.2.2f1). No matter how to import it, my IDE, both Visual Studio and JetBrains Rider, would give an error when I try using NSubstitute
saying NSubstitute is undefined.
I have tried many options and versions of NSubstitute packages (4.2.1 and 2.0.3). I also import the dll file from net35 folder of the package into a Plugins folder in my Unity project. I also tried to install the same version of NSubstitute using Nuget in the IDE.
Upvotes: 7
Views: 7079
Reputation: 1183
Someone decided to make it easy for NSubstitute to work with Unity, and did all the heavy lifting. Here's the github repo with instructions to get it working with v5.1 in a couple simple steps: https://github.com/Thundernerd/Unity3D-NSubstitute
I installed using the Add package from git url
option and worked like a charm!
Upvotes: 1
Reputation: 13622
Update 2020
If you read this in 2020 or later, check the answer from Rodrigo Eleuterio how to make this work with the latest version of NSubstitute.
/end update
I was able to make the 2.0.3 version work with Unity. The newer versions have additional dependencies which I could not make work in Unity, so it seems for now we're stuck with 2.0.3. So here is how I did it:
lib/net35/NSubstitute.dll
into the Plugins
folder of your project.When you now reopen the project in Rider it should be found. Sometimes Unity acts up a little and doesn't seem to find the DLL. In this case re-importing the project can help.
Upvotes: 2
Reputation: 86
I added NSubstitute 4.2.1 (.NET Standard 2.0) in a Unity project, but I needed to include 3 more dependencies for it to work:
Upvotes: 7