Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by athap · Sep 04, 2011 at 09:05 PM · testingassembly

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 !!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TomHunt · May 02, 2012 at 04:59 PM 0
Share

I'm experiencing a similar issue in my code. I'd like to not have to expose a whole bunch of internal object state as public just for the purposes of testing, while at the same time be able to use it to verify correct internal functioning of the class via automated tests.

I have tried "using System.Runtime.CompilerServices" per the $$anonymous$$SDN documentation, but still get the "type or namespace name 'InternalsVisibleTo' could not be found.' error message. So it would seem that either this is not implemented in Unity's version of the .NET runtime or it is misplaced.

Can anyone shed some further insight into this matter?

Thanks

avatar image athap · May 03, 2012 at 12:20 AM 0
Share

Hi $$anonymous$$,

Well this is not an answer but I was not able to solve this issue. I simple changed internal to public.

Thanks

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by hejaaa · Jun 26, 2020 at 02:32 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by peterpan2022 · Jul 25, 2021 at 07:12 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to separate unit tests into another C# project? 1 Answer

Tests cannot find classes 0 Answers

Can we create playmode tests outside of the main build assembly? 0 Answers

Adding Game Assembly causes type or namespace errors 0 Answers

Test-Runner and Assembly Definitions conflict with Third-Party assets 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges