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

Abstract class unit test

1 Answer 198 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 22 Mar 2011, 04:17 PM
I'm evaluating JustMock and have some unit tests that I want to write against an abstract base class. I wish to test some functionality in the base class. Can JustMock create a concrete class in which I can test with or do I need to implement a derived class myself? I want the base class method called, I just would like to know if JustMock provides any support here.

1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 24 Mar 2011, 09:07 AM
Hi Ryan,

Thanks for bringing up the question. Yes you can mock members from abstract base class. Here i have created an abstract class :

public abstract class FooBase
{
    public abstract void Submit();
}

For that i simulated the following test that worked as expected:

var foo = Mock.Create<FooBase>();
bool called = false;
Mock.Arrange(() => foo.Submit()).DoInstead(() => called = true);
foo.Submit();
Assert.IsTrue(called);

It is also possible to mock virtual members from abstract base class if it is implemented in another class that is used as the target.


Hope this information is useful.

Kind Regards,
Ricky
the Telerik team

Tags
General Discussions
Asked by
Ryan
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or