SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    Jul 2006
    Location
    finland
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    how to define mocks to void-methods

    Hello!

    How do I define Mock-objects to void type methods?

  2. #2
    Senior Member
    Join Date
    Jan 2007
    Location
    Castle Grayskull
    Posts
    388
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to define mocks to void-methods

    I think you'll need to understand the objects who have access to functions that call those void functions to understand how they are used in the program. Instantiate a class that has public/private functions that can call a void() function (or maybe they're void themself) and see how those private/public funcions operate...if the void() function allows one to pass in values try a few values and see how it handles them.

    I suppose the other thing you could do is step-through the code seeing what statements are executed based on various inputs. This would give you an idea about who is calling these void functions. In some scenarios/code-bases though this is totally impractical.

    It's been 9 years since R&D/unit testing were a daily duty. You should really get on a development message board or ask your friendly developer about this question though.

    Or maybe this isn't much help....I'm not incredibly strong on unit testing at this level-of-depth but I thought I'd throw out as much info I do know on this subject.
    Reserve a few months every so often and preview retirement throughout your career. You won't regret that a 35 year career was reduced to 34 years to take vacations measured in months in order to remember what a stress and care-free life is all about.

    Books and hard work will get you anywhere you want to go.

  3. #3
    Junior Member
    Join Date
    Jul 2006
    Location
    finland
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to define mocks to void-methods

    Okay!

    Thank you for information. I think that void-type methods can be mocked if I know the behavior of code. For example if void-type method creates instances or set:s some values, the HOLE usage should be mocked as you said.

    But if I want to automate the mocking prosess, how I read automatically the source code and detect what should be mocked?

  4. #4
    Junior Member
    Join Date
    May 2007
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to define mocks to void-methods

    Basically Mock objects do two things:
    <ul type="square">[*]return some default value when a method is called, or throw an exception to see if the calling code handles it well[*]check that a method is called, how many times, and perhaps check the values that were passed to it[/list]
    With a void type method you can't generate a return value,
    but you may still throw an exception to check error handling
    by the code that calls the method. And you can of course still
    do the second check, namely checking how many times it is
    called and with what values.
    If I'd asked the customers what they wanted, they would have said "A faster horse." -- Henry Ford

  5. #5
    Junior Member
    Join Date
    May 2007
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to define mocks to void-methods

    [ QUOTE ]
    I suppose the other thing you could do is step-through the code seeing what statements are executed based on various inputs. This would give you an idea about who is calling these void functions. In some scenarios/code-bases though this is totally impractical.

    [/ QUOTE ]

    I'm afraid that is the opposite of what unit tests are meant for, i.e. testing without having to step through the code. Unit tests allow you to check that everything still works fine if you modify some code. If you have to step through the code every time you modify code, it gets boring and you waste a lot of time - and most programmers will likely stop doing it.

    So write good unit tests instead.
    If I'd asked the customers what they wanted, they would have said "A faster horse." -- Henry Ford

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 10:06 PM.

Copyright BetaSoft Inc.