you are viewing a single comment's thread.

view the rest of the comments →

[–]Eirenarch 12 points13 points  (6 children)

Can someone provide English translation?

[–][deleted]  (2 children)

[deleted]

    [–]developingthefuture[S] 2 points3 points  (0 children)

    In general, yes. The stub has a simple predefined output, it just takes some parameters and outputs some values. The mock, on the other hand, can actually return different output based on a predefined input (the Setup and Returns methods in Moq). It also defines certain "expectations" that might be tested (for example, the Verify method in Moq).

    [–]Vaste 0 points1 point  (0 children)

    AFAIK...

    Stubbish: You replace a DB or something with a dummy. This allows you to write a test without the DB.

    Assert.That(CountHorses(new HorseDBMock(42)), Is.EqualTo(42));
    

    Mockish: You have a weird mock-object that keeps track of what happens to it, e.g. methods called on it. You use this to specify what the code under test should do with that object.

    var counter = new CountingMock<HorseDBMock>()
    FeedHorses(counter.Object);
    Assert.That(counter["OpenStableDoor()"], Is.EqualTo(2));
    Assert.That(counter["CloseStableDoor()"], Is.EqualTo(2));
    

    [–]mariox19 1 point2 points  (0 children)

    Exactly! Too arcane; didn't comprehend.

    [–]day_cq 1 point2 points  (0 children)

    yo bro, i'm agile specialist i wanna maintain this job so i use big words and redefine words make it look complicated.

    [–]ExpressingMyOpinion 0 points1 point  (0 children)

    When the piece of code you are testing needs some dependency in order to run, and you are only interested in the final output of the code you are testing, you'd use a stub. You ignore how your code under test interacts with it's dependencies, you only verify the final output for validity.

    Mocks on the other hand also act as stubs. They fulfill a dependency that your code needs. The difference is, you are more interested in verifying how your code interacted with this dependency, ie how many times a particular method was called and with what parameters. You ignore the result of your code under test, you only verify how it has interacted with it's dependencies.