Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by sschoellhammer · Dec 31, 2014 at 07:30 AM · nunit

Nunit NotNull assert strangeness

Hello!

I'm started using Nunit.framework to do my tests - for example I check if everything is assigned properly in Awake():

 public GameObject test;
 // Use this for initialization
 void Start () {
     Debug.Log(test == null);
     Assert.IsNull(test);
 }

the variable test is not assigned, so the two printouts for these statements are first true (as expected) but the second is :

 AssertionException:   Expected: null
   But was:  <null>

What does this mean? Is there some other type of null?

If I now explicitly set test to null, it all just works as expected, which let me to believe there is a difference between not assigning something in the editor and it being null.

Thanks for any clarification!

Seb

Comment
Add comment · Show 3
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 AlwaysSunny · Dec 30, 2014 at 10:50 PM 0
Share

I'd start by searching the plugin documentation. Questions about plugins are generally best directed to the author or any community they offer. null is null, there's no special type of null. I couldn't guess at what the issue is without the documentation.

avatar image sschoellhammer · Dec 30, 2014 at 10:57 PM 0
Share

I should have added that (I'll edit the question), if I explicitly assign null like so: test = null; it works as expected.

avatar image AlwaysSunny · Dec 31, 2014 at 03:13 AM 0
Share

What does the documentation have to say about this problem? Sorry to say, it's fairly unlikely to get plugin help here unless it's a very prolific plugin.

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Landern · Dec 31, 2014 at 07:32 AM

In the back end(unity implementation) the gameobject isn't techincally null. They override the operators(!=, == .Equals, etc) to derive a value that is meaningful through your implementation, but if Assert.IsNull is literally taking the Object and checking null, you will be surprised. You can see this by adding a breakpoint into a location in your script/code that you assume an unassigned gameobject should be null, but you will find it isn't in the sense that it will just display null, it will have property like it was instantiated and all that jazz. Do it, check it out.

Behold a screen: Unity Nulls Not Null

You can see where this has been asked previously:

http://answers.unity3d.com/questions/524998/testing-for-null-bug-or-feature.html

http://forum.unity3d.com/threads/fun-with-null.148090/

http://answers.unity3d.com/questions/794152/gameobject-not-null-before-instantiate.html

http://forum.unity3d.com/threads/null-check-inconsistency-c.220649/

http://forum.unity3d.com/threads/components-and-gameobject-evaluate-to-null-after-destroyed-except-w-interfaces.158196/


nulls unity.png (110.0 kB)
Comment
Add comment · Show 2 · 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 sschoellhammer · Dec 31, 2014 at 08:32 AM 0
Share

Hi Landern, thanks a lot for the answer. Wow. How interesting - and confusing! :) I'll have to change my sanity functions ..

avatar image refardeon · Jun 01, 2018 at 11:41 AM 1
Share

Thank you for this! This might be obvious, but if anybody else runs into this like I just did, here is a simple workaround to use ins$$anonymous$$d of Assert.IsNull:

 Assert.IsTrue(objectThatShouldBeNull == null); 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Debugging unit tests with Monodevelop 0 Answers

The Assembly is referenced, But the dll is not allowed to be included or could not be found 0 Answers

Marking a directory as a development dependency 1 Answer

Unity NavMeshComponents Errors 1 Answer

Run unit tests (nUnit) in debug mode (MonoDevelop) 0 Answers


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