Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
1
Question by cgeopapa · Jul 24, 2015 at 09:45 AM · unity 5testingintegrationtools

How to run tests that require Input?

Hello, so resently I downloaded unity testing tools and since I heard/read that they are so useful I desided to make a TDD project.

But I have a question:

How do I make integration tests that require input?

Like when the player presses the left arrow the character turns left? Or when the player kills 10 enemies the game ends?

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
3

Answer by Barbog · Jul 29, 2015 at 07:46 PM

Essentially, you don't. What you'll be wanting to do is to decouple your code from the actual input and instead rely on the results of the input. This can be done by separating all the non-Unity API code from that which does use the Unity API and then put a layer in-between the two. Then you can have a test object in your integration test which takes the place of the actual input. The Unity team has a great blog post which goes into similar types of decoupling in decent detail here

Comment
Add comment · Show 2 · 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 maxi297 · Sep 24, 2015 at 07:17 AM 1
Share

I know this is kinda old post, but I would like to give my input (bad pun) on cgeopapa's post and your answer. I do understand your point. Logic should be extracted from $$anonymous$$onoBehaviour objects and tested as unit tests.

However, I feel like cgeopapa's point is still valid. It is good to know every class is working individually but if you want to test the interaction between components (basically integration testing), you might want to simulate user input. Not everything can be tested as unit tests. Why can this be useful? I would like to give a simple example: Let say I have this code sample which makes my character jumps when space key is pressed: void Update() { if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space)) { character.jump(); } } Here, all the logic regarding the jump is in the method jump of Character (Can he jump? Is he grounded?, etc...) However, if I delete the line character.jump(); accidently, my character won't jump anymore when the space key is entered. I would like to be notified by a failing test on this because I really want my character to jump when it happens.

I would like Unity Test Tools to have a way to create inputs (something like "at X seconds, for y seconds, simulate keydown). Right now, you could do your own wrapper around Unity input (like shown on this post) but I don't feel it is a good idea to change your code only to test. Some might say that you change code only for testing purposes when you do this, but I feel it is more like a good practice to allow maintanable code by separation responsabilities.

avatar image YoungDeveloper maxi297 · Sep 24, 2015 at 07:23 AM 0
Share

For best results you'd eventually want to write centralized Input $$anonymous$$anagers, which should only be tested once. Everything else should be written on top of that and test it's own logic and not input.

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

24 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

Related Questions

Unity 5.6, Testrunner, Edit mode, how to run tests automatically on compile 1 Answer

Chartboost with Unity 5 linking error 2 Answers

Unity Test Tools Integration Tests with Jenkins 1 Answer

Problem Integration Facebook with Unity 5 On Android 0 Answers

Where should I put my Unit Tests? 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