InternalsVisibleTo in Unity

Hi Unity members,

For unit testing I am trying to use InternalsVisibleTo(“assemblyname”) in Unity 3d without any success.

Has anyone ever used it in Unity ?

Here is the problem.

[assembly: InternalsVisibleTo("Test")]
namespace Dev
{
  public class Example
  {
    internal bool Function(){ //do stuff }
  }
}

namespace Test
{
  public class TestExample
  {
    Example example = new Example();
    bool value = example.Function();//Error Cannot access "Function" due to its
                                    //protection level
  }
}

When I open this project in .Net 2008, .Net compiler does not give ANY error.

Note : In the documentation for InternalVisibleTo, its written that this is a new class for .Net 2.

Thanks for reading !!

2 Answers

2

My problem, and I think OPs problem, is the difference between an assembly name and a namespace. We feed a namespace to InternalsVisibleTo. But it is expecting the name of an assembly.

It is old question, but for answer, I suppose you need use correct assembly name. But for better order assemblies you need create AssemblyInfo.cs file and there write something like this:

using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("UCM_uTests")]

This is necessarily use for Testing. Use just public accessors with various assemblies is wrong because other programmer can implement this code wrong.