#Unity Tests

1 messages · Page 1 of 1 (latest)

drowsy pumice
#

Good morning everybody. I discovered tests in Unity and I am pretty excited to put these into action. However, I cannot seem to get the tests to recognize the classes I have built, even though the appear to be fine elsewhere in the project.

Radians.cs

using System;

namespace Trig // I tried with and without the namespace, neither worked.
{
    public static class Radians
    /* To Be Tested */
    {
        public static double ToDegrees(double d)
        /* To Be Tested */
        {
            Radian radians = new Radian(d);
            return radians.ToDegrees();
        }
        public static double FromDegrees(double d)
        /* To Be Tested */
        {
            return d * Math.PI / 180.0;
        }
        public static double Coefficient(double d)
        /* To Be Tested */
        {
            return d/Math.PI;
        }
    }
}

Radians.spec.cs

using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using Trig;

public class RadiansTest
{
    // A Test behaves as an ordinary method
    [Test]
    public void RadiansSimplePasses()
    {
        // Use the Assert class to test conditions
        double coefficient = Radians.Coefficient(0.5); // Access the static field correctly
        Assert.AreEqual(180.0 / System.Math.PI, coefficient);
    }

    // A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
    // `yield return null;` to skip a frame.
    [UnityTest]
    public IEnumerator RadiansWithEnumeratorPasses()
    {
        // Use the Assert class to test conditions.
        // Use yield to skip a frame.
        yield return null;
    }
}
#

This is the error I get

Assets\StudioDMB\VectorPP\Scripts\Tests\Radians.spec.cs(12,34): error CS0103: The name 'Radians' does not exist in the current context
#

And I get this one && the one above when I try to use the namespace

Assets\Scripts\Scratch.cs(2,7): error CS0246: The type or namespace name 'Trig' could not be found (are you missing a using directive or an assembly reference?)
gentle isle
#

Sounds like you use assembly definitions

drowsy pumice
gentle isle
#

I would assume you have them. Alternatively you might be missing required using declarations?

#

The most common reason is assembly definitions at least

drowsy pumice
#

How do I configure my assembly definitions?

drowsy pumice
scarlet forge
#

I THINK UnityTests requires asmdefs

gentle isle
#

Yeah I would assume that if you don't use them at all, it doesn't matter. However, perhaps they are simply required here

scarlet forge
#

vaguely remembering something that was said on the server rather recently

drowsy pumice
drowsy pumice
#

Thanks! That gives me a place to start.

#

Does anybody happen to know of a good tutorial on this topic off hand? The quality of tutorials is -- varied.

drowsy pumice
#

I am back where I started.

Assets\Tests\VectorPP\VectorPPTests.cs(13,9): error CS0103: The name 'Radians' does not exist in the current context
#

Success!

#

And then, when you do have the definitions, VSCode will not be able to recognize it for reasons that elude me.