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 /
  • Help Room /
avatar image
0
Question by Shayalp1 · Nov 04, 2020 at 11:16 AM · testingunit

Why am I getting these error messages in my Unit Test?

Hi, I'm still in the learning phase of Unit Testing in Unity and after 2 weeks of struggling I managed to code my test that work for my game project and I don't seem to understand why I'm getting these error messages. Can someone please assist me?

So these are my test codes:

 using System.Collections;
 using System.Collections.Generic;
 using NUnit.Framework;
 using UnityEngine;
 using UnityEngine.TestTools;
 
 [TestFixture]
 public class TestSuite{
 
     private GameObject testObject;
     private HookMovement hookMovement;
 
     [SetUp]
     public void Setup()
     {
         testObject = GameObject.Instantiate(new GameObject());
     }
 
     [UnityTest]
     public IEnumerator Verifying_For_All_The_Active_Items_In_The_Scene()
     {
         UnityEngine.SceneManagement.SceneManager.LoadScene("Gameplay");
 
         yield return new WaitForSeconds(5);
 
         //Arrange
         var blueGem = GameObject.FindGameObjectWithTag("BlueGem");
         var pinkGem = GameObject.FindGameObjectWithTag("PinkGem");
         var lightBlueGem = GameObject.FindGameObjectWithTag("LightBlueGem");
         var purpleGem = GameObject.FindGameObjectWithTag("PurpleGem");
         var greenGem = GameObject.FindGameObjectWithTag("GreenGem");
         var orangeGem = GameObject.FindGameObjectWithTag("OrangeGem");
         var cashBag = GameObject.FindGameObjectWithTag("CashBag");
         var largeStone = GameObject.FindGameObjectWithTag("LargeStone");
         var smallStone = GameObject.FindGameObjectWithTag("SmallStone");
 
         //Act
         if (blueGem != null) Debug.Log("GameObject: " + blueGem.tag + " is active");
         if (pinkGem != null) Debug.Log("GameObject: " + pinkGem.tag + " is active");
         if (lightBlueGem != null) Debug.Log("GameObject: " + lightBlueGem.tag + " is active");
         if (purpleGem != null) Debug.Log("GameObject: " + purpleGem.tag + " is active");
         if (greenGem != null) Debug.Log("GameObject: " + greenGem.tag + " is active");
         if (orangeGem != null) Debug.Log("GameObject: " + orangeGem.tag + " is active");
         if (cashBag != null) Debug.Log("GameObject: " + cashBag.tag + " is active");
         if (largeStone != null) Debug.Log("GameObject: " + largeStone.tag + " is active");
         if (smallStone != null) Debug.Log("GameObject: " + smallStone.tag + " is active");
 
         //Assert
         Assert.AreEqual("BlueGem", blueGem.tag);
         Assert.AreEqual("PinkGem", pinkGem.tag);
         Assert.AreEqual("LightBlueGem", lightBlueGem.tag);
         Assert.AreEqual("PurpleGem", purpleGem.tag);
         Assert.AreEqual("GreenGem", greenGem.tag);
         Assert.AreEqual("OrangeGem", orangeGem.tag);
         Assert.AreEqual("CashBag", cashBag.tag);
         Assert.AreEqual("LargeStone", largeStone.tag);
         Assert.AreEqual("SmallStone", smallStone.tag);
 
         yield return new WaitForSeconds(5);
     }
 
     [UnityTest]
     public IEnumerator Verifying_If_The_Hook_Stops_Swinging_When_Triggered()
     {
         yield return new WaitForSeconds(1);
 
         hookMovement = testObject.AddComponent<HookMovement>();
         if (hookMovement.canRotate = false) Debug.Log("The hook has stopped swinging");
         Assert.IsFalse(hookMovement.canRotate);
     }
 
     [UnityTest]
     public IEnumerator Verifying_If_The_Hook_Drops_When_Triggered()
     {
 
         yield return new WaitForSeconds(1);
 
         hookMovement = testObject.AddComponent<HookMovement>();
         if (hookMovement.moveDown = true) Debug.Log("The hook has moved down");
         Assert.IsTrue(hookMovement.moveDown);
     }
 
 }
 

So here's the thing, the game plays during the testing and I am able to trigger the hook to move down, so both my unit test for (Verifying_If_The_Hook_Stops_Swinging_When_Triggered) and (Verifying_If_The_Hook_Drops_When_Triggered) passes without the need for me to simulate a mouse click in the test code. However, (Verifying_For_All_The_Active_Items_In_The_Scene) fails and gives a error "System.NullReferenceException : Object reference not set to an instance of an object"

I also get this error "MissingReferenceException: The object of type 'GameplayManager' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. GameplayManager.DisplayScore (System.Int32 scoreValue) (at Assets/Scripts/Helper Scripts/GameplayManager.cs:87) Item.OnDisable () (at Assets/Scripts/Item Scripts/Item.cs:19)"

This is the code on line 87 in the Gameplay Manager Script:

 StopCoroutine("Countdown");


This is the code on line 19 in the Item Script:

 GameplayManager.instance.DisplayScore(scoreValue);

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

0 Replies

· Add your reply
  • Sort: 

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

210 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 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 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

Unit test: PlayerPrefs, Attempted to access a missing method. 1 Answer

Testing on Genymotion: Grey Scene except Canvas items 1 Answer

Failed to get a line number for unity test method. So please find it in opened file in external editor 1 Answer

One person has reported that the game freezes in a strange way while testing, please help 0 Answers

Load file during Unit Test 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