Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by MookeeDev · Sep 10, 2020 at 04:28 PM · testingplaymodetestunittest

How to load a scene in PlayMode tests

I need to load a scene to use it for PlayMode unit tests.

But when I add the following code:

 [SetUp]
 public void SetUp(){
     SceneManager.LoadScene("MainScene");
 }

all the tests fail.

Even stuff that should always be true fails in test runner, like the line

 Assert.AreEqual(true, true);

My question is: how can I load scenes in PlayMode tests?

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

Answer by jtok4j · Sep 10, 2020 at 05:35 PM

Greetings,

Just curious whether you have a line which calls SetUp() ?

Example:

 Setup() ; 

Would need to be called like the above in a script when something happens. So, if you never actuall call/run Setup() it will never do the scene loading. Sorry, it's a bit hard to troubleshoot without seeing any other code used.

Keep on Creating!

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 MookeeDev · Sep 11, 2020 at 03:00 PM 0
Share

Unity TestRunner automatically calls the function with attribute [SetUp].

avatar image jtok4j MookeeDev · Sep 11, 2020 at 04:30 PM 0
Share

Now add this line, ( after: Scene$$anonymous$$anager.LoadScene("$$anonymous$$ainScene"); ) and check the console when in Play$$anonymous$$ode after you thing TestRunner has called the SetUp function.

 debug.log("Just called the Setup() Function") ; 


This will print "Just called the Setup() Function" when the Setup function is called. If this doesn't appear in the Console, you'll know that Setup isn't actually being called.

avatar image MookeeDev jtok4j · Sep 12, 2020 at 01:11 PM 0
Share

Thanks, but you misunderstood my question. The scene definitely loads, I can see it load on the screen.(Yes I also tested it with Debug.Log() ). The problem is that loading the scene causes all unit tests to always fail.

$$anonymous$$y question is why does this happen and how can I load scenes in unit tests and have the tests work normally.

avatar image
0

Answer by unity_399E6EDE23F69583CC01 · May 19 at 11:04 AM

In case anyone stumbles upon this, I found another tag called [OneTimeSetUp] to use instead of [SetUp]. I don't have a anything to test this with so I don't know if it works, but it's worth a shot

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

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

139 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

Related Questions

Can we create playmode tests outside of the main build assembly? 0 Answers

How to implement mandatory cleanup for the Unity PlayMode tests? 1 Answer

TestRunner playmode IPrebuildSetup test doesn't run 1 Answer

Unity Test Runner doesn't cleanup previous test results 1 Answer

Unity 5.6 Unit Testing 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