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

Question Asmdefs: What's the proper way to add new plugins when you also have tests?

Discussion in 'Testing & Automation' started by AcademyOfFetishes, Mar 9, 2019.

  1. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    To get tests to work, I had to create an Assets/Scripts/Scripts.asmdef and a Assets/Tests/Tests.asmdef The Tests depend on the Scripts, but not vice versa.

    I believe because of this, every time I add a new library/plugin/etc. things get weird. I'll use a current example: I tried to get Fungus installed (if you don't know what that is, it's probably not important). As soon as I did, I got an error in one of its classes saying
    TooltipAttribute.tooltip
    doesn't exist. I find that confusing because the documentation says it does, but my VS says that it has a .text instead. Whatever, I changed it, and now everything compiles, all my tests pass, yay.

    Now, when I try to use Fungus, it gives me this error:
    I found those classes here:

    And I figure this means that Fungus is outside of Scripts.asmdef, so it's like not accessible to the script code? My solution is to create an asmdef for Fungus and have Scripts.asmdef depend on it. I created the Fungus.asmdef here:

    On closer inspection, it's saying that all the stuff in Fungus/.../Editor needs to be in Assets/Editor. I'm very confused by this, because I thought the way Editor directories work is, they can be anywhere as long as they're named Editor.

    I took the whole Fungus/.../Editor directory and copied its contents into Assets/Editor.

    That seems to have fixed everything. No more errors. BUT, I feel like all this manual work is very, very wrong. Can someone explain to me what's going on and why I have to do these steps to get my project to work correctly?

    I don't know what's going on so I may not have provided enough information for you guys/gals to help me. Just let me know. Here's the inspector of all 3 asmdefs:



     
    Last edited: Mar 9, 2019
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    Because you have an asmdef in your 'Scripts' folder, everything under that is going into a 'Scripts' assembly. The magic behaviour around folders named 'Editor' is overridden by the presence of the asmdef.

    What you're supposed to do is to add another asmdef, inside the Editor folder, which you set up to only include the Editor platform.
     
  3. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    Which Editor folder should I put that in?
     
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    In any Editor folder which is inside some other folder with an asmdef (i.e. any folder inside your Scripts folder, because that's where you put your asmdef).
     
  5. noio

    noio

    Joined:
    Dec 17, 2013
    Posts:
    226
    This is honestly kind of annoying.

    As soon as I start using tests in my projects, my "Scripts" folder needs an .asmdef, which means that suddenly I need to start going through all the plugins and add .asmdef's for them too, and for their Editor folders separately, etc.

    Such a hassle!

    Also, I really don't want to do any editing of the plugins myself, because that might be reverted when I update a plugin.