开发者

different mock objects to compare objects in unit tests

I have Equals method tha开发者_如何学Pythont I am trying to tests. this method return true if object passed to is is same as this object.

I test true condition as following.

        var mocks = new MockRepository();
        var mockActionAlert = mocks.StrictMock<ActionAlert>();
        var mockActionAlert2 = mocks.StrictMock<ActionAlert>();
        bool comparer = mockActionAlert.Equals(mockActionAlert2);
        Assert.Equal(true, comparer);

However, how can I get a different mock object to test that equal method returns false.

Thank You,


What you have shown doesn't appear to make any sense at all.

You only have mocks in your test code - no real implementations at all.

Not only are you not testing anything real, but since you are using mocks, your can even decide whether your pretend tests should fail or not.

To do what (I think) you want, simply create an ActionAlert (one from you real code, not a mock of one) and then create a second ActionAlert with properties that should make it equal using your Equals method. Pass the second ActionAlert in and assert that the result is true (Probably best to use Assert.True() since that is more expressive of intent).

Then when testing that the Equals method returns false, write tests with ActionAlerts with properties that make them not equals. No need for mocks at all.

The place where you need mocks is where you have depenendencies in your classes under test that you want to either assert some behaviour on (has a dependence method been called in a certain way) or you want some predifined behaviour from (make a method return a certain value when called).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜