Search Unity

Unit testing collision

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

  1. Erenquin


    Apr 9, 2018
    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:

    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.

    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.

    Last edited: Jan 8, 2020