Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
7
Question by Cerzi · Oct 22, 2017 at 02:47 PM · testing

Installed Unity Test runner but can't access NSubstitute

All the resources on how to use unity's test runner talk about using NSubstitute to mock objects, which sounds great, but not a single one explains how to actually get NSubstitute working with unity. It isn't included with the test runner (using 2017.2) (although NUnit is). Installing it to visual studio using NuGet doesn't work because the dependencies are all messed up.

Is something wrong with my unity install? This is driving me insane!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Kyle-h · Oct 26, 2017 at 12:13 AM

I believe it was removed from the Testing tools when they were merged with Unity.

https://github.com/nsubstitute/NSubstitute/releases

I was looking into this as well, download the lastest from the link above. Add it in your Editor folder as Import new Asset... pull the dll from the NET35 folder

I'm on windows and had to use visual studio, as vs code did not recognize NSubstitute for some reason.

Also checkout this:

https://www.youtube.com/watch?v=xSa2S-W7x48

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

Answer by Eli-Davis · Aug 05, 2019 at 02:04 PM

For anyone seeing this in the future, for Unity 2018 you'll need Version 2 of the NSubstitue Nuget Package

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image timoffex · Sep 14, 2019 at 10:24 PM 0
Share

This is the right answer! Get it here https://www.nuget.org/packages/NSubstitute/2.0.3. I tried getting 4.2.1 and even got the assembly dependencies (Castle.Core, System.Threading.Tasks.Extensions and System.Runtime.CompilerServices.Unsafe), but that did not work: Unity kept logging an error saying "Unloaded broken assembly ...".

avatar image
2

Answer by Amheklerior · Sep 28, 2019 at 11:06 AM

I'm actually having a similar problem.

I imported the NSubstitute.dll i found inside the net35 folder of the package, into the Unity project, but Unity does not recognize it.

Importing the NSubstitute package directly from Visual Studio, allow the IDE to recognize it but only as soon as I jump again into the Unity Editor, the code recompiles and the NSubstitute package is not recognized anymore giving me compilation errors (for using Substitute).

I tried with both .NET Standard 2.0 and .NET 4.x configurations for the Api Compatibility Level on the Player Tab under the Project settings.

Thanks in advance for any reply :)


OS: Windows 10 (64bit)

Version of Unity used: 2019.2.3f1.

Versions of NSubstitute tried: 4.2.1 / 4.0.0 / 2.0.3.


UPDATE: problem solved.

I worked a bit on it and I managed to find the solution to the issue.
I discovered that the NSubstitute .dll file that I added to the project is not 'automatically' visible to the test code.

In order to make it so, it has been enough to reference the NSubstitute .dll file from the assembly definition in the test folder, under the Assembly Reference section - where the reference to NUnit dll is -.

This was the missing piece for me. I hope this note will be helpful to others that might reach this post as well.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by sonnyb · May 26, 2021 at 03:56 PM

It's also possible to get the latest version 4 of NSubstitute working by adding NSubstitute's dependency DLLs to the Plugins folder.


See this Stack Overflow answer.

I had to add these DLLs:

  • NSubstitute.dll

  • System.Threading.Tasks.Extensions.dll

  • Castle.Core.dll


Note that I tested with netstandard 2.0 DLL files with ".NET 4.x" API Compatibility Level project setting on Unity 2020.


I found it easiest to get all the required DLLs by installing NSubstitute via the NuGet package manager which pulls in the dependencies.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlasYorick · Oct 27, 2021 at 01:25 AM 1
Share

You're a lifesaver - Unity was complaining about NSubstitute but only in one assembly and only on a single machine at our studio. Adding Castle.Core to the assembly resolved the issue.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

76 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

iOS development on PC 1 Answer

Testing for Active Internet Connection 4 Answers

Unit Testing Rigidbody2D without polluting scene with gameobjects 1 Answer

Unit Testing MonoBehaviour.Assertion component not Working with property. 2 Answers

Android game testing, using Unity Remote 4 NOT working 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges