Search Unity

Unit testing collision

Discussion in 'Testing & Automation' started by Erenquin, Jan 8, 2020.

  1. Erenquin

    Erenquin

    Joined:
    Apr 9, 2018
    Posts:
    42
    Hello,
    As the title implies, I'd like to unit test collision.

    I do not catch "OnCollisionEnter" in the game script (understand: no variable is set or modified like in a case of "attackDamage").
    I just want to ensure that the collision occurs (that, for example, I do not disable or remove the collider component on one object).

    I searched google but can't find a solution.
    I only found this 3 years old post that says it is not possible:
    https://forum.unity.com/threads/unity-test-tools.218287/page-6#post-2916609

    So, is it still impossible ? And if it is possible, can someone guide me how to ?

    While writing this I found out the "Rigidbody.SweepTest" API. Could I use an "Assert true SweepTest" ?
    This would not truly test OnCollisionEnter but may do the trick.

    [Edit]
    Just made a trial with "Sweep test" and it seems working.
    If I disable the collider the test fails and if I enable it it passes.

    Thanks.
     
    Last edited: Jan 8, 2020
unityunity