This is a migrated thread and some comments may be shown as answers.

Testing a Protected Method is called

2 Answers 469 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 11 May 2015, 09:19 AM

I've found a couple of articles about testing protected methods and have written the appropriate code to do so.

However, now I want to test my class, which includes a public abstract method, to ensure, when the abstract method is called in this particular implementation, that one or more protected methods are called. Something like this ...

01.public abstract class MyBaseClass
02.{
03.    protected void Foo(){ /* stuff */ }
04.    protected void Bar(){ /* stuff */ }
05.     
06.    public abstract void Stuff();
07.}
08. 
09.public class MyClass : MyBaseClass
10.{
11.    public override void Stuff()
12.    {
13.        Bar();
14.    }
15.}

 

In this trivial example I want my test to ensure that Bar() is called.

 Can I actually do this?

2 Answers, 1 is accepted

Sort by
0
Stuart Hemming
Top achievements
Rank 2
answered on 11 May 2015, 10:21 AM
0
Stefan
Telerik team
answered on 12 May 2015, 08:26 AM
Hello Stuart,

I'm glad that the documentation proved useful to you.

Regards,
Stefan
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
General Discussions
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Stuart Hemming
Top achievements
Rank 2
Stefan
Telerik team
Share this question
or