How to unit test a method that has void as return type

You may also like...

3 Responses

  1. Ramon Smits says:

    Why not make use of inheritence?

    I usually just inherit the class do that is has access to protected stuff. This new class is then an internal subclass in my unittest.

    You are using interface so your imlementation methods should be marked virtual which they currently are not. 🙂

  2. Ramon Smits says:

    2nd, why not just create a mock? Then you also can validate that the repository save is actually called.

  3. Dennis van der Stelt says:

    lol, are you going to comment everything!? 😉
    I’m making a series of posts with examples like these.
    About the virtual methods, you’re right. I forgot.

    And about the mock, I’m doing state-based testing here. I know that when writing mocks like these yourself, you can also mark a boolean that some method has been accessed. A mocking framework is even better yet, but I’m trying to keep things as easy as possible. But I’ll add an example with a mocking framework in it as well. The original idea though, started with someone asking me about how to have mocks and inject those with Unity. So I thought, let’s write some posts on it.

Click on a tab to select how you'd like to leave your comment

Leave a Reply

Your email address will not be published. Required fields are marked *