0

I have many methods that are defined internal like so:

internal static string GetAJobShaNaNaNaShaNaNaNaNaNa(string Silhouettes)

However, in order to call them from a test project added to the solution, I need to change their access modifier from internal to public.

Is there a non-tedious way to make these methods public to the tests, yet remain internal otherwise?

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 2
    Just ran out of close votes, so I'll leave this here for someone else: http://stackoverflow.com/questions/358196/c-sharp-internal-access-modifier-when-doing-unit-testing – Cody Gray - on strike Feb 25 '16 at 17:13
  • 1
    If you truly need to test internal methods, and not just their public interfaces, then you can use the `InternalsVisibleTo` attribute. – Cody Gray - on strike Feb 25 '16 at 17:14

2 Answers2

9

Why not add InternalsVisibleTo in your assembly to allow the tests access?

[assembly:InternalsVisibleTo("YourTestAssembly")]
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
1

You can use internalsvisibletoattribute. https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx

neo
  • 425
  • 3
  • 11