Forum rules - please read before posting.

Unit Testing AC extensions

Hello,

I am developing an Unity package that uses Adventure Creator. I would like to write unit tests using the Unity's unit testing framework. How should I go about building the tests? How easy is it to "mock" the AC scene with global variables? Or should I create an empty scene and load that in the beginning of the test?

I have done something like this, already. How to go about adding global variables in this case? Thank you!

    [SetUp]
    public void Setup()
    {
        if (EventSystem.current == null) {
            EventSystem.current = new GameObject("EventSystem", typeof(EventSystem), typeof(StandaloneInputModule)).GetComponent<EventSystem>();
        }

        var ks = new KickStarter();
        ks.Initialise();
        go = new GameObject();
        target = go.AddComponent<NGHMenu>();
        // combine path with test directory
        target.hintsPath = Path.Combine(TestHelper.GetTestDirectory(), "fixtures", "test01");
        CreateSampleObject();
        target.guideSample = sampleObject;
    }

Comments

  • For an AC scene to run correctly, you need:

    • A MainCamera component attached to the scene Main Camera
    • A GameEngine object to be present

    The GameEngine object includes the KickStarter component, as well as other components that handle scene-specific data and behaviour. You can either add the prefab from AC's Prefab/Automatic folder, or view it to see what components need to be manually added.

  • Thank you for the direction where to go. I managed to setup the AC GameEngine like this:

        [SetUp]
        public void Setup()
        {
            var sm = ScriptableObject.CreateInstance<SceneManager>();
            var mainCamOb = SceneManager.AddPrefab("Automatic", "MainCamera", false, false, false);
            sm.InitialiseObjects(false); // do not create folders
    

    This creates the SceneManager object and the required MainCamera. The
    InitialiseObjects will then create the necessary components. No scene file needed or anything. And the KickStarter now has the managers in place and I can do this inside the test, for example:

    KickStarter.runtimeVariables.globalVars.Add(new GVar() { label = item.Key, BooleanValue = item.Value, type = VariableType.Boolean })
    

    Hope this helps someone facing the same situation.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.