• 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

1 Reply

· 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.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

138 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

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

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges