Abstract class unit test

2 posts, 0 answers
  1. Ryan
    Ryan avatar
    2 posts
    Member since:
    Mar 2011

    Posted 22 Mar 2011 Link to this post

    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.
  2. Ricky
    Ricky avatar
    467 posts

    Posted 24 Mar 2011 Link to this post

    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);

    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,
    the Telerik team

Back to Top