Search Unity

Unit Testing missing assembly reference false-positive?

Discussion in 'Scripting' started by CosmicGiant, Jan 22, 2019.

  1. CosmicGiant

    CosmicGiant

    Joined:
    Jul 22, 2014
    Posts:
    23
    Trying to create unit tests for a collection of extension methods I'm making, but I get
    [class] does not contain definition for ...
    errors in VS if the assembly assembly is not included through it, and I get
    The type or namespace name 'XenoRo' could not be found (are you missing a using directive or an assembly reference?)
    in the editor when I do include the assembly.

    Example:
    Code (CSharp):
    1. using NUnit.Framework;
    2. using UnityEngine;
    3.  
    4. namespace Tests {
    5.     public class Vector3ExtensionsTests {
    6.         #region Methods
    7.         [Test]
    8.         public void WithXReturnsCorrectValue() {
    9.             var vector = Random.onUnitSphere;
    10.             var x = Random.value;
    11.  
    12.             var expected = vector;
    13.             expected.x = x;
    14.             var result = vector.WithX(x);
    15.             Assert.That(result == expected);
    16.         }
    17.         #endregion
    18.     }
    19. }
    ...Errors on
    .WithX(x)
    and suggests fix by including assembly reference to
    Assembly-CSharp-firstpass
    , but if I tell VS to implemente the fix, it then errors in-editor saying that the namespace could not be found.

    What is wrong? And how to fix?