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

Resolved Is it Good Practice to Include Unit Tests in Package Submissions?

Discussion in 'Assets and Asset Store' started by andycodes, Jan 28, 2023.

  1. andycodes

    andycodes

    Joined:
    Jan 22, 2013
    Posts:
    39
    I have a few small editor tools that I'd like to start writing unit tests for going forward. I have experience writing unit tests in other languages and have started to look into UTF.

    My main question with this is if it's good practice to include unit test files within the package itself, or keep those separate within the development unity project. Would including test files create any headaches for users or cause the package to be rejected during review?

    Thanks!
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,060
    It‘s up to you and whether you want to provide these code snippets to users. If you don‘t want that, the common approach is to make a separate package just for the tests. Many Unity packages follow this model.

    PS: I am talking about Package Manager packages. In case you want to distribute via Unity Asset Store you should know that it doesn‘t (yet) use those packages but the old .unitypackage format.
     
    andycodes likes this.
  3. dajnoo

    dajnoo

    Joined:
    Jun 9, 2018
    Posts:
    40
    Including unit tests in your package is a best practice in software development. It demonstrates a commitment to quality assurance and helps users understand how the asset is intended to be used. The test files can also serve as a testament to the quality of the code and, if designed well, can even be reused by others.

    In case a user wants to remove the test folder, it's a quick and straightforward process that can be done in just a few clicks. The benefits of including unit tests in your package far outweigh any potential drawbacks, making it an essential practice.

    The Unity review process is unlikely to be impacted by the presence of test files, so don't hesitate to include them in your package.

    Good luck with your project!
     
    andycodes likes this.
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,531
    In 10+ years on the Asset Store, I'm only aware of one user who used the unit tests available for a Pixel Crushers asset. (It's possible there are more that I'm not aware of.) I assume most users expect the publisher to thoroughly test their assets before publishing.

    As CodeSmile suggests, consider including them in a unitypackage. That way you won't break the user's project with compiler errors if they don't have the Test Framework package installed in their project. If your tests use a significant amount of test data, you could alternatively make the unitypackage available for download from your publisher website.
     
    andycodes likes this.
  5. dajnoo

    dajnoo

    Joined:
    Jun 9, 2018
    Posts:
    40
    Even if the Test Framework is uninstalled, the edit mode tests won't cause any errors.
     
    andycodes and TonyLi like this.
  6. andycodes

    andycodes

    Joined:
    Jan 22, 2013
    Posts:
    39
    Awesome, thanks for the insights everyone!