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
6
Question by movexig · Apr 29, 2014 at 12:28 PM · testingnunit

Asynchronous unit testing

Unity recently released their suite of testing tools (http://blogs.unity3d.com/2013/12/18/unity-test-tools-released/). These tools include NUnit for unit testing, which I want to make use of.

The component being tested performs various asynchronous tasks. These tasks use the Unity scheduler (coroutines, yield, invoke etc.) and signal completion via callbacks. To verify that this works correctly, I need the unit test to wait for the task to complete before asserting.

However, because these tasks use the Unity scheduler, I cannot simply block in the unit test until the tasks complete, since that blocks the main thread and thus the scheduler, and so the task will never complete. But if I return from the unit test, to free up the main thread, the test will complete before the callback has arrived and any assertions are made.

How can I run asynchronous processes that require the Unity main thread to not be blocked in a unit test with NUnit/Unity's test tools?

Comment
Add comment · Show 1
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 Xtro · May 21, 2015 at 07:44 PM 0
Share

We need async unit test support in Unity Test Tools :(

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by liortal · May 20, 2014 at 08:54 PM

Sounds like what you're doing is not a unit test at all. It has too many external dependencies on the Unity engine.

A unit test runs in isolation and shouldn't rely on anything else, making it deterministic.

See this tutorial for basic setup for integration tests using Unity Test Tools: http://wp.me/p4kypp-6s

Comment
Add comment · Show 4 · 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 Xtro · May 21, 2015 at 07:43 PM 1
Share

Unity testing on a async method is not wrong and it's not an integration test. Unfortunately, Unity Test Tools doesn't seem to support async unity testing.

Fore example, Unity has a class called WWW for http requests. If you want to unity test a method which uses WWW class, you won't be able to do it with Unity test tools because WWW class is async.

avatar image liortal · May 21, 2015 at 08:08 PM 0
Share

Different people use different definitions. I consider an integration test as a test involving the interaction between 2 different classes (or systems). In this case, your own code working with the WWW class is considered (by me) to be an integration between these 2 components. What kind of test would you like to perform ? there's nothing preventing you from starting a coroutine just for testing and waiting for it to complete (or whatever you need to test).

avatar image Xtro · May 22, 2015 at 12:26 AM 0
Share

If you implement your own async class and if you want to unit test it, you want be able to do so, not because it's dependent on another class, just because it's async. This is not about different definitions. Unity test tools doesn't support async unit testing unfortunately.

avatar image santiihoyos Xtro · Aug 09, 2016 at 12:26 PM 0
Share

yes i have this problem when i tried to implement UNET tests.

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

23 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

Related Questions

Can Unity 5.6's Test Runner optionally output NUnit 2 xml format? 2 Answers

How can I run Unity tests with some defined nUnit category 2 Answers

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

Change the maximum length of a method name in the Test Runner Editor 0 Answers

Unit Test Tools and building from MonoDevelop 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