Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved UTT: AssertionComponent won't mark test as successful if it checks a value from another gameobject

Discussion in 'Testing & Automation' started by Garm, Aug 10, 2016.

  1. Garm

    Garm

    Joined:
    Jan 22, 2013
    Posts:
    5
    Not sure if that's the right forum, but as far as I know Unity Test Tools is made by Unity team.

    I recently started to experiment with UTT and stumbled across a problem that I can't solve:
    When I create AssertionComponent from code (using IntegrationTest annotations) and check some value of the component that isn't attached to the same GameObject as AssertionComponent, it won't return "Success" to the Integration Test Runner and will simply timeout itself.

    It does perform check as far as I can tell, since it will throw an assert exception and mark test as "Failed" if conditions of the assert weren't met.

    Here's some modified example code from the UTT package to help me illustrate the issue:
    http://pastebin.com/xzpEAU3k

    Most likely I'm missing something but for now such behavior is odd to me.

    Thanks.
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    When the test starts, it will get all the assertion components on the test game object:
    upload_2016-8-12_9-59-22.png

    Note that the assertion components are on the test game object (the one with the TestComponent on it), you are adding the assertion component to the test object in your scene.
     
    Garm likes this.
  3. Garm

    Garm

    Joined:
    Jan 22, 2013
    Posts:
    5
    Yes, that's what I did.

    So I run a debugger (it didn't work for me previously for some reason), and what I found out is that on CreateAssertionComponent<T> method, AsserionComponent will be created on the gameObject that is passed as the parameter.



    There is an overload of the method that would take two gameobjects as parameters, but it would use second one only for comparison.

    I guess I'll have to create an overload like this?

    private static T CreateAssertionComponent<T>(out IAssertionComponentConfigurator configurator, CheckMethod checkOnMethods, GameObject originObject, GameObject gameObject, string propertyPath) where T : ActionBase

    var ac = originObject.AddComponent<AssertionComponent>();

    Am I right?
     
    Last edited: Aug 12, 2016
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    These methods are just helpers.. you can create something on your own that will do the comparison.
     
    Garm likes this.
  5. Garm

    Garm

    Joined:
    Jan 22, 2013
    Posts:
    5
    Sure, I just wanted to use the utilities provided by the unity team.

    Anyhow, I created overloads for Create and CreateAssertionComponent that take additional GameObject parameter (reference to gameObject with TestComponent on it) and now everything seems to work. Thanks.
     
    liortal likes this.