To mock or not to mock the argument of the testing function?











up vote
-1
down vote

favorite












Let's say i want to test a function calculateHealth(person) . And let's say the function take a person model argument and return a number from 0% to 100% depending on how healthy the person is. Lets say the person model is costly to create since it has many properties and sub models which also have many properties. I feel like i should mock the person out and substitute it with a simpler version of a person that only behave enough to test my calculateHealth() function. But according to an expert's oppinion (Justin Searls – Please don’t mock me - https://www.youtube.com/watch?v=Af4M8GMoxi4, at 28:14 ) it is a smell if we mock the model value out( for him, it is only ok to mock out dependency but not the model value )



If i have more test like this, it is costly to maintain them if my person model change. What is your opinion?










share|improve this question


























    up vote
    -1
    down vote

    favorite












    Let's say i want to test a function calculateHealth(person) . And let's say the function take a person model argument and return a number from 0% to 100% depending on how healthy the person is. Lets say the person model is costly to create since it has many properties and sub models which also have many properties. I feel like i should mock the person out and substitute it with a simpler version of a person that only behave enough to test my calculateHealth() function. But according to an expert's oppinion (Justin Searls – Please don’t mock me - https://www.youtube.com/watch?v=Af4M8GMoxi4, at 28:14 ) it is a smell if we mock the model value out( for him, it is only ok to mock out dependency but not the model value )



    If i have more test like this, it is costly to maintain them if my person model change. What is your opinion?










    share|improve this question
























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      Let's say i want to test a function calculateHealth(person) . And let's say the function take a person model argument and return a number from 0% to 100% depending on how healthy the person is. Lets say the person model is costly to create since it has many properties and sub models which also have many properties. I feel like i should mock the person out and substitute it with a simpler version of a person that only behave enough to test my calculateHealth() function. But according to an expert's oppinion (Justin Searls – Please don’t mock me - https://www.youtube.com/watch?v=Af4M8GMoxi4, at 28:14 ) it is a smell if we mock the model value out( for him, it is only ok to mock out dependency but not the model value )



      If i have more test like this, it is costly to maintain them if my person model change. What is your opinion?










      share|improve this question













      Let's say i want to test a function calculateHealth(person) . And let's say the function take a person model argument and return a number from 0% to 100% depending on how healthy the person is. Lets say the person model is costly to create since it has many properties and sub models which also have many properties. I feel like i should mock the person out and substitute it with a simpler version of a person that only behave enough to test my calculateHealth() function. But according to an expert's oppinion (Justin Searls – Please don’t mock me - https://www.youtube.com/watch?v=Af4M8GMoxi4, at 28:14 ) it is a smell if we mock the model value out( for him, it is only ok to mock out dependency but not the model value )



      If i have more test like this, it is costly to maintain them if my person model change. What is your opinion?







      unit-testing testing mocking






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 17 at 7:39









      Lu Tran

      486




      486
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Since person is complicated to mock, the test for calculateHealth() prove to be difficult. This is a design smell and not the test problem. Instead of passing in a black box person , i should define the interface more clearly, and preferably simple to use and to mock/test.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349246%2fto-mock-or-not-to-mock-the-argument-of-the-testing-function%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Since person is complicated to mock, the test for calculateHealth() prove to be difficult. This is a design smell and not the test problem. Instead of passing in a black box person , i should define the interface more clearly, and preferably simple to use and to mock/test.






            share|improve this answer

























              up vote
              0
              down vote













              Since person is complicated to mock, the test for calculateHealth() prove to be difficult. This is a design smell and not the test problem. Instead of passing in a black box person , i should define the interface more clearly, and preferably simple to use and to mock/test.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Since person is complicated to mock, the test for calculateHealth() prove to be difficult. This is a design smell and not the test problem. Instead of passing in a black box person , i should define the interface more clearly, and preferably simple to use and to mock/test.






                share|improve this answer












                Since person is complicated to mock, the test for calculateHealth() prove to be difficult. This is a design smell and not the test problem. Instead of passing in a black box person , i should define the interface more clearly, and preferably simple to use and to mock/test.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 18 at 19:41









                Lu Tran

                486




                486






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349246%2fto-mock-or-not-to-mock-the-argument-of-the-testing-function%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    Origin of the phrase “under your belt”?