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

When to use Unit Testing?

Discussion in 'General Discussion' started by Shack_Man, Dec 11, 2018.

  1. Shack_Man

    Shack_Man

    Joined:
    Jun 7, 2017
    Posts:
    365
    Almost simultaneously I came across Unit Testing in the book "Clean Code" and in a tutorial from Unity3D.college:




    I've been doing tons of Unity tutorials yet never heard this being mentioned. I assume this is because a tutorial is not a live and flexible project but more like a presentation of finished code. So my question is how common is it to use Unit Testing when developing a game in Unity? I assume scope plays an important role but same could be said for keeping code clean and the above mentioned book tells me that there is absolutely no excuse for bad habits.
    I also read in a blog post (c# but not Unity) that writing a Unit Test can sometimes make you spot badly designed code. All that plus the fact that Unit Testing would have come in handy many times in the past makes me believe I should use it from now on in every project.

    Any thoughts from you more experienced folks on that?

    Thanks!
     
  2. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Game developers are years behind corp devs sadly so its not very common. We do it, but we have background in corp dev
     
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,903
    - when you're working on public facing API
    - you're working on public asset
    - you have a lot of time and you don't now how to do automated feature tests instead
     
  4. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Scenario tests / spec tests does not replace unit testing, two different things
     
  5. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,903
    Oh really? I wouldn't know that if you don't enlighten me. :D LOL
     
  6. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    It feels like this thread is a can of worms waiting to be spilled :p

    For starters, I'm not sure there even is a general consensus on what exactly a "unit" is. A single function? An entire class (i.e. an object)? A module?

    Either way, I wouldn't stress over semantics. In fact, I believe it's exactly these kind of worries that make people obsess over what should go into unit testing and what shouldn't, and that ends up costing too much time, so they end up avoiding it altogether. And well, if you don't test your code, that's a bad habit in itself :D
     
  7. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Our game is so complex so doing scenario testing is basicly impossible . We do mostly unit testing on the domain and the network API (in-house networking api ) and the like