Search Unity

How to setup ASMDEF so it doesn't cause compile errors when NUnit (Test Runner) is not available?

Discussion in 'Testing & Automation' started by Xarbrough, Mar 17, 2022.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I have several testing assemblies (ASMDEF) in a shared code utilities package and I want to set it up so that it still compiles even when certain Unity features (modules, packages) are disabled. If I remove the Test Runner package and all other packages I'm left with an error, because the assembly reference for nunit.framework.dll can no longer be found. Ideally, I'd like to simply use a "Define Constraint" on the ASMDEF to not compile my test assembly if the DLL is not found. How can I do this?

    The following does not work:
    upload_2022-3-17_16-24-57.png

    When I remove the Test Runner package, the custom assembly is still compiled:
    upload_2022-3-17_16-26-9.png

    Alternatively, I wondered, if I could separate the dependency on NUnit from the TestRunner. Currently not sure, but it might be that I'm not using much of the test runner's features, so I could try to only reference the custom Unity NUnit directly. Would that be possible?
     
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Well, as these things go, I found my answer by experimenting right after I posted my question:

    upload_2022-3-17_16-35-58.png

    It is possible to use a Version Define in the Define Constraints fields. That was unintuitive for me because I would have guessed that the assembly would first be compiled to generate the version defines, but apparently it works fine. I can now exclude testing assemblies if the Nunit extension wasn't found. :)
     
    MrLucid72, Wappenull and Dextozz like this.