Search Unity

Question PlayMode tests in Assembly-CSharp (with UTF 1.3.7)

Discussion in 'Testing & Automation' started by liortal, Jul 17, 2023.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    We recently upgraded to UTF 1.3.7. We have play mode tests in our Assembly-CSharp assembly (due to legacy reasons). Since the upgrade our build process is failing with compilation errors (fails to find UnityTest attribute).

    I know this is related to the upgrade, so i'd like to ask the following questions:
    1. Is the scenario of keeping tests (playmode) under Assembly-CSharp still supported (with 1.3.7 release) ?
    2. I suspect that our build fails since the UTF assembly is marked with a scripting define (which is probably not set anywhere in our project - UNITY_TESTS_FRAMEWORK - can / should we set it to make our build work as before ?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,901
    As long as I an remember tests had to have their own assembly. This is mainly to ensure that test code and anything the tests reference are not included in builds.

    This script define is what prevents tests from included in builds if I remember correctly. So if you set that your whole project would become a test. ;)

    Try to put your testcode under a test assembly. You will need to add all dependencies to the asmdef and then it should work again - provided there aren’t any dependency cycles where non-testcode references testcode.
     
  3. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    It's difficult as most of our code is still in the built-in Assembly-CSharp and so we cannot create an assembly just for tests (it won't be able to reference any code). Looking for workarounds at the moment.
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,901
    You can create one assembly for your code, add all necessary dependencies and off you go, ;)