Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Complex unit tests inside Unity?

Discussion in 'Scripting' started by Quested, Nov 1, 2018.

  1. Quested

    Quested

    Joined:
    May 23, 2013
    Posts:
    13
    Hey,

    I'm looking for a way to do unit tests inside Unity. I came across a few tutorials and the "Test Runner", but from what I have seen they all seem to be very basic. They can do assertions like I would expect, but they load the tests in a new empty scene. I would like to have a scene that I can manually create specifically for unit tests. For example a scene where a rifle is facing an enemy and one rifle facing an enemy behind cover. That would enable me to call the shoot method in my unit test for both rifles and check the health of both enemies. Only being able to test in empty scenes is kinda pointless, in my opinion. I don't need to test that my LoseHealth method removes Health, I would like to test more complicated scenarios and see if Reloading after a reload animation works. For that I want a custom scene. Is this possible with built in tools or third party tools? A good tutorial would be great too, I watched a few tutorials, but they all only tested very basic stuff in empty scenes, like if an Addition method works, which is not really helpful for a complex game.

    Best Regards
    Niklas Werner
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,580
    Not sure where is the problem?
    From what you describe, you have examples checked already.
    Why you cannot extract what you need and assemble your system for testing, adding trigger, health etc. as you need?
    In the end, you need them build anyway, if you make such game.
     
  3. Quested

    Quested

    Joined:
    May 23, 2013
    Posts:
    13
    As I already said, Unity creates a new empty scene when executing the unit tests. I did not found a way to customize this scene or manually create it. So I can't add any trigger, collider or mesh to the unit tests.