• 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 erap129 · Dec 07, 2017 at 10:44 AM · editor-scriptingonguitestingtestunittest

Testing editor scripting

Hello, I created a tool for Unity using editor scripting (my tool is a window which allows the user to create certain gameobjects). I want to create unit tests to test the functionality of this window - but my problem is that in order to properly test the functionality of the window I need the OnGUI() function to run (to simulate a mouse movement or something similar). This is an example of a test I want to run:

      [UnityTest]
         public IEnumerator testMonoScriptInit()
         {
             GameObject go = (GameObject)Resources.Load("Tests/Sphere");
             AssetCreatorWindow acw = (AssetCreatorWindow)ScriptableObject.CreateInstance(typeof(AssetCreatorWindow));
             acw.Construct(go);
             yield return null; //continue 1 frame
             acw.DrawAssetSettings();
             Assert.AreNotEqual(acw.getMonoscripts(), null);
         }

In my example - AssetCreatorWindow acw is an instance of the window I am testing. I used yield return null even though I'm not sure what it does, anyway the problem is that I need to run acw.DrawAssetSettings() and this function utilizes GUI functions - so the tester won't run them (because GUI functions can only be called from OnGUI()) Is there anyway to run OnGUI() from code? I can't just call it because it is not a public method... Thanks all.

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 NoBrainer-David · Apr 14, 2018 at 10:07 AM

What exact functionality do you want to test that happens inside of DrawAssetSettings()? I would suggest pulling that functionality out of OnGUI() into it's own function. Then, both your AssetCreatorWindow and the test method testMonoScriptInit can call it.

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.

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

82 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

Related Questions

Unity 5.6 Unit Testing 1 Answer

How to load a scene in PlayMode tests 1 Answer

How to Run Editor Test Runner test from editor script in 5.6? 4 Answers

Is it possible to prevent AssertionComponent from being stripped out of non-dev builds? 1 Answer

How to implement UNET Test? 0 Answers

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