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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Lonsomehell · Jun 15, 2015 at 06:00 PM · apitestingintegrationmonobehavior

Unit Testing MonoBehaviour.Assertion component not Working with property.

Everyone knows that you can't use new with MonoBehaviour. What I am doing is put everything that doesn't use the unity API inside another class then reference it. This left me with MonoBehaviours that uses only the other class. Is this the correct way to go.

Update

This time I had a problem with the integration tests. I have a code that goes like this.

     class Foo : MonoBehavior{
     
     public GameObject AGameObject{
        get{ return bar.AGameObject}
        set{ bar.AGameObject = value}
        
     AnotherClass bar;
 
     void Start(){
        bar = new AnotherClass ();
     }
 }

 

I get when I use the Assertion Component:

Unexpected top level layout group! Missing GUILayout.EndScrollView/EndVertical/EndHorizontal? UnityEditor.DockArea:OnGUI()

Any Help ?

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

2 Replies

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

Answer by Lonsomehell · Jun 17, 2015 at 06:27 AM

For the update I was able to solve the problem. I have to test for null value.

 class Foo : MonoBehavior{
      
      public GameObject AGameObject{
         get
         { 
              If(bar == null)
                 return null;
              return bar.AGameObject;
         }
         set
         { 
              If(bar == null)
                 bar = new AnotherClass ();
              bar.AGameObject = value;
         }
         
      AnotherClass bar;
  
      void Start(){
         if(bar == null)
             bar = new AnotherClass ();
      }
  }
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
2

Answer by Tomek-Paszek · Jun 15, 2015 at 06:38 PM

Hey!

Your approach is fine. There is nothing wrong with decoupling game logic from Unity API :) I've written a blog post about it, check it out: http://blogs.unity3d.com/2014/06/03/unit-testing-part-2-unit-testing-monobehaviours/

Tomek

Comment
Add comment · Show 3 · 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 Lonsomehell · Jun 16, 2015 at 01:09 AM 0
Share

Good Day sir,Actually I was following your blog post.It is a great post. But testing like this felt kinda weird and unnatural. I am still a new developer and this is my first time writing unit tests. Any other advice would be great.

avatar image Tomek-Paszek ♦♦ · Jun 16, 2015 at 08:17 AM 0
Share

I understand that it might feel like your not doing it the easiest way and you're writing a lot of unnecessary code but for the moment there is no 'easy' way to unit test $$anonymous$$Bs. There is nothing wrong with writing a little bit more of the code in order to keep your logic decoupled. I think you will get used to it quickly and you will stop noticing it :)

avatar image Lonsomehell · Jun 16, 2015 at 08:52 PM 0
Share

Thanks for your reply. At least I know know that this is not going to be trivial at the beginning.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity Test Tools Integration Tests with Jenkins 1 Answer

FB.Apprequest problem 0 Answers

Dynamic Integration test error - Not found skipping/KeyNotFoundException 0 Answers

How to make MonoBehavior class testable with NSubstitute? 2 Answers

Unity Test Tools - Integration Test for existing scenes 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