Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Solved] Test Specific dependency / exclude certain folder of package when dependency not provided

Discussion in 'Package Manager' started by as3mbus, Mar 19, 2020.

  1. as3mbus

    as3mbus

    Joined:
    Dec 5, 2016
    Posts:
    71
    so i am trying to include test to my package, and i am using nsubstitute in my test suite to ease mocking abstract class. but then i find out that it would make most of my package dependent to nsubstitute even though it's only depend when unit test is run.

    i've separated test folder from implementation and added specific asmdef for it as well.
    i'm okay to unable to test the code when nsubstitute isn't available.

    Note : i'm using unity 2018.4 so version defines isn't available yet
    although it's not available can i configure unity to ignore certain asmdef folder when a dependency aren't present ?

    thank you beforehand
     
    ArthurAulicino likes this.
  2. Davidtr_Unity

    Davidtr_Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    34
    Hi @as3mbus,

    Do the tests in your package need to run in your main game project? If not, you could install nsubstitute in your "package project" to run tests, doing so wouldn't automatically include nsubstitute when installing your package in your main project unless you explicitly add it as a dependency in the package manifest. Tests in the `Tests` folder are not automatically imported when installing a package so you wouldn't have any reference to nsubstitute in the context of your main project, as implied in Adding tests to a package.
     
  3. as3mbus

    as3mbus

    Joined:
    Dec 5, 2016
    Posts:
    71
    thanks for reply

    i am still confused with term of "Package Project"

    am i supposed to create new unity project for each project ?
    somehow i think the answer is yes. thus leading to more question. how do i reference the package through git if this "package project" would have assets folder and additional package/manifest file ?
    (in short : how do i provide git repository with it's package alone without including basic unity structure ?)

    ah so `Tests` folder won't automatically included when you install it.
    so it means i need to manually supply required dll when i decided that i want to include the test inside it ?
     
    Last edited: Mar 20, 2020
  4. Davidtr_Unity

    Davidtr_Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    34
    It's common practice when developing a package to have an accompanying test project. This is what I meant by "package project", sorry for the confusing term, let's call it a test project from now on :). Having a separate project for tests can be useful if you don't want test dependencies into your main project.

    I am not sure exactly what you mean by "referencing this package through git [...] without including basic unity structure". I assume you don't want the test project to be included when adding your package to Unity. It won't be an easy task until proper support for subfolders (which is coming very soon!) but until then you might not even have to worry about it considering assets that are not in the "Runtime" and "Editor" folders of the package are gonna be ignored by Unity.

    As for including the "Tests" folder, it's not imported unless explicitly configured in the manifest file. It’s a per-project configuration that can be done in the manifest.json file. See Enabling tests for a package in the manual.
     
  5. as3mbus

    as3mbus

    Joined:
    Dec 5, 2016
    Posts:
    71
    is this "Test Project" are unity project ? since if it is would it have project setting, and packages folder in it's root directory.
    which is the reason of my confusing question on `how to reference the package through git` when package.json is located inside assets folder

    are this supposed to happen on unity 2019 and later ? since i haven't used runtime and editor convention in 2018 and everything still get imported (outside of tests folder)

    the tests folder functionality work like a charm so i guess it solved my problem.

    but i'm still interested with how this `Test Project` should be