0

Is it possible to execute a test method that is inside a base class from the base class itself??

I have a base class which is declared as abstract and there is one test method inside this. I want to execute this test method in base class.

While i do this. test case shows "Not runnable"

4
  • Sample code? What test framework are you using? Commented Sep 6, 2013 at 13:49
  • can you share some code? Commented Sep 6, 2013 at 13:49
  • Put the code that you are using in the question. Commented Sep 6, 2013 at 13:49
  • And indicate what test framework / runner you are using... Commented Sep 6, 2013 at 13:52

3 Answers 3

2

You can't create an instance of an abstract class. You will most likely have to create an empty class that inherits from the base and call the methods from there.

The only other alternative, which to me seems like a lot more work, is to use a mocking framework that supports doing this. For instance:

http://ayende.com/wiki/Rhino+Mocks+Partial+Mocks.ashx?AspxAutoDetectCookieSupport=1

Sign up to request clarification or add additional context in comments.

Comments

1

Derive a class in your test from the base class. In derived class create a method that calls base class's method. Now you can instantiate the test class, I'll do a property example (just to make you work and do the same for the method, as you haven't posted your code :) )

//this could be created in your unit tests proj public class MyBaseClassExtended : MyBaseClass { public MyBaseClassExtended () : base() { } public new object SomeProperty { get { return base.SomeProperty; } } //now I can test [Test] public void Test() { var x= new MyBaseClassExtended (); Assert.IsNotNull(x.SomeProperty); 

Comments

1

of course you can't test that and you can't have an instance an abstract class.

if you feel like you need to do that, then you should reconsider your design and change it accordingly.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.