Importing NSubstitute into Unity project

我是研究僧i 提交于 2021-02-19 08:21:57

问题


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.


回答1:


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:

  • Download 2.0.3 from the NuGet Website.
  • Unzip the file and move the lib/net35/NSubstitude.dll into the Plugins folder of your project.
  • In your test assembly definition, don't forget to reference it, otherwise it will not be found.

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.




回答2:


I has added NSubstitute 4.2.1 (netstandard 2.0) in a Unity project, but I needed to include more 3 dependences to work:

  1. system.threading.tasks.extensions.4.5.3
  2. system.runtime.compilerservices.unsafe.4.6.0
  3. castle.core.4.4.0


来源:https://stackoverflow.com/questions/57784897/importing-nsubstitute-into-unity-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!