- Home /
executing "unity test tools" tests both fail and pass + warning
[Test]
public void Blaa()
{
Bla b = Substitute.For<Bla>();
Assert.AreEqual(5, b.Get5());
}
This test passes in the unity editor and fails in VS(executing using ReSharper). Why?
Also as far as I read in the net, Substitute is used for object mocking and I decided to use it in order not to get the
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
warning. Still I get it, even if I'm not instantiating the object the normal way but with substitute. Why?
Answer by Tomek-Paszek · Feb 25, 2015 at 08:30 AM
Hi @MapuHoB,
VS is using it's own nUnit runner and therefore some of the Unity code might not work. The reason for that is that the Unity code (like MonoBehaviour) needs to be run in the Editor to work properly.
To answer your second question: NSubstitute is still instantiating the object behind the curtain.
Tomek
Thanks for the response! Just 1 more thing that I need to ask in order for my curiosity to shut the front door. I noticed that although we can't create new isntances of $$anonymous$$Behaviour with the new keyword and we get an warning that we can't, in the tests we can do this and it shows that the tests pass. Does this mean that we can use the new keyword ins$$anonymous$$d of Substitude?(Sorry if I haven't read somewhere that this has been said or haven't understood smth)
Instantiating $$anonymous$$onoBehaviours with new keyword can be unpredictable and you shouldn't do it. I'm not 100% sure what are the consequences.
Your answer

Follow this Question
Related Questions
How to run tests that require Input? 1 Answer
Debugging tools that can be used with Unity in Native OS and multithreading envi? 0 Answers
Running Unity Test Tools in build system 0 Answers
Unity 5.6, Testrunner, Edit mode, how to run tests automatically on compile 1 Answer
The type or namespace name `SceneManagment' does not exist in the namespace 1 Answer