Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Testing MonoBehaviours in a Package

Discussion in 'Scripting' started by psxcode, Jul 24, 2020.

  1. psxcode

    psxcode

    Joined:
    Jan 26, 2014
    Posts:
    26
    Hi! I'm working on a package.
    It has MonoBehaviour scripts in it.
    I'm trying to test these MB scripts.
    I decided to setup Test Scenes with certain states, load them during the Test, and to assert results.
    • I tried PlayMode Tests. To SceneManager.LoadScene and to assert results.
      The issue:
      Unity wants these Scenes to be added to BuildSettings.
      I cannot do this, because this is a package.

    • I tried EditorTests with EditorSceneManager.OpenScene
      The issue:
      OpenScene requires a path to a scene, and it cannot find my scene in Packages folder

    • Instead of scenes, I could Instantiate prefabs from my Tests folder. The issue: AssetDatabase cannot find assets in Packages folder.
    The question!
    How to setup Tests in a Package with several MonoBehaviours instantiated in a Scene-like or Prefab-like structure?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
  3. psxcode

    psxcode

    Joined:
    Jan 26, 2014
    Posts:
    26
    Hi PraetorBlue! Thanks.
    Yes, I'm trying to apply Unity Testing framework to a Package.
    For now, I'm gonna continue with PlayMode tests...
    Maybe someone would come up with better approach to testing a package.