As a unit test, an implementation detail such as caching

So, I have a class with the following method:

public class SomeClass
{
    ...

    private SomeDependency m_dependency;

    public int DoStuff()
    {
        int result = 0;
        ...
        int someValue = m_dependency.GrabValue();
        ...
        return result;
    }  
}

And I decided that instead of calling every time m_dependency.GrabValue(), I really want to cache the value in memory (i.e. in this class), since every time we get the same value (the dependency leaves and captures some data from the table, which is almost never changes).

I ran into problems trying to describe this new behavior in unit test. I tried the following (I am using NUnit with RhinoMocks):

[Test]
public void CacheThatValue()
{
    var depend = MockRepository.GeneraMock<SomeDependency>();

    depend.Expect(d => d.GrabValue()).Repeat.Once().Return(1);

    var sut = new SomeCLass(depend);
    int result = sut.DoStuff();
    result = sut.DoStuff();
    depend.VerifyAllExpectations();
}

This, however, does not work; this test passes even without making any changes to the functionality. What am I doing wrong?

+5
source share
2

, Do (ing) Stuff. , SomeDependency, - ( , - - yum).

, DoStuff , , . SomeDependency . , , , , .

, . .

, , - , . "0". , :

depend.Expect(d => d.GrabValue()).Repeat.Once().Return(1);
depend.Expect(d => d.GrabValue()).Repeat.Never();

/, .

+5

, " ". SubDependency , , , ( , ) - , SubDependency, ( "" ). , - , , .

, - - , . . ?

+4

All Articles