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

Editing "Test framework" source code in your project

Discussion in 'Testing & Automation' started by liortal, Oct 20, 2019.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    The Unity test framework is now a package, which means you get the source code for playing around with it!
    BUT... how do you edit the code if you want to make changes? i did not find a nice way (i am a developer which means i am also lazy).

    Here's a short editor code snippet that allows you to right-click any package to include (embed) it into your project. After running this you can edit the package source code :)
    Code (CSharp):
    1. using System.IO;
    2. using UnityEditor;
    3. using UnityEditor.PackageManager;
    4. using UnityEngine;
    5.  
    6. public static class ImportPackage
    7. {
    8.     [MenuItem("Assets/Embed Package")]
    9.     public static void EmbedPackage()
    10.     {
    11.         var selection = Selection.activeObject;
    12.         var packageName = Path.GetFileName(AssetDatabase.GetAssetPath(selection));
    13.  
    14.         Debug.Log($"Embedding package '{packageName}' into the project.");
    15.      
    16.         Client.Embed(packageName);
    17.      
    18.         AssetDatabase.Refresh();
    19.     }
    20.  
    21.     [MenuItem("Assets/Embed Package", true)]
    22.     public static bool EmbedPackageValidation()
    23.     {
    24.         var selection = Selection.activeObject;
    25.  
    26.         return selection != null && AssetDatabase.GetAssetPath(selection).StartsWith("Packages/");
    27.     }
    28. }
    Please note that the package icon does not change, IMHO it should look different to reflect that this is a "local" copy of the package:

    upload_2019-10-20_14-11-0.png
     
    Xarbrough likes this.