How totestinternalprotectmethodsinc#

50 %
50 %
Information about How totestinternalprotectmethodsinc#

Published on February 24, 2014

Author: ltcrd


How to test internal / protected methods in c# Howard 2014/02/13

Modifiers • internal • The internal keyword is an access modifier for types and type members. Internal types or members are accessible only within files in the same assembly • protected • The protected keyword is a member access modifier. A protected member is accessible within its class and by derived class instances.


How to test internal methods?

How to test internal methods? • InternalsVisibleToAttribute • • Specifies that types that are ordinarily visible only within the current assembly are visible to a specified assembly. Namespace: System.Runtime.CompilerServices

How to test internal methods?

How to test internal methods?

How to test protected methods?

How to test protected methods? • 繼承 TestClass 後 • 覆寫要測試的方法並將其 modifier 設為 public • 測試 public method

How to test protected methods?

new Modifier • When used as a declaration modifier, the new keyword explicitly hides a member that is inherited from a base class. • When you hide an inherited member, the derived version of the member replaces the base class version. • Although you can hide members without using the new modifier, you get a compiler warning. If you use new to explicitly hide a member, it suppresses this warning.

How to test protected methods? – better solution! Set method modifier to protected internal, and use InternalsVisibleToAttribute • protected internal: Access is limited to the current assembly or types derived from the containing class.

References • How to Test Private and Protected methods in .NET • • InternalsVisibleToAttribute Class • • Modifiers • • • new Modifier

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...