Print Page | Close Window

Favor manual

Printed From: PHAworkers Online
Category: General
Forum Name: Rumor Mill
Forum Discription: Discuss/Debunk what you've heard somewhere.
URL: http://www.phaworkers.org/forum//forum_posts.asp?TID=6028
Printed Date: Sep 11 2025 at 1:54pm
Software Version: Web Wiz Forums 8.03 - http://www.webwizforums.com


Topic: Favor manual
Posted By: ksosjdjlis
Subject: Favor manual
Date Posted: Feb 22 2013 at 5:45pm
etc lead to test overspecification

In Osherove's great book "The Art of Unit Testing" one of the test anti-patterns is over-specification which is basically the same as testing the internal state of the object instead of some expected output. To my experience, http://hzqcyjycom.wybhost.5uhezu.com.cn/bbs/forum.php?mod=viewthread&tid=2250740 - http://hzqcyjycom.wybhost.5uhezu.com.cn/bbs/forum.php?mod=viewthread&tid=2250740 , using Isolation frameworks can cause the same unwanted side effects as testing internal behavior because one tends to only implement the behavior necessary to make your stub interact with the object under test, http://news.163yxj.com/plus/view.php?aid=34951 - http://news.163yxj.com/plus/view.php?aid=34951 , http://www.ballgownsoutlet.com/ - http://www.ballgownsoutlet.com/ . Now if your implementation changes later on (but the contract remains the same), your test will suddenly break because you are expecting some data from the stub which was not implemented.

So what do you think is the best approach to counter this?

1) Implement your stubs/mocks fully, this has the negative side-effect of potentially making your test less readable and also specifying more than necessary to make your test pass.

2) Favor manual, fully implemented fakes.

3) Implement your stubs/fakes so that they make your test just pass, and then deal with the brittleness that this might introduce.

I tend to use mocks instead of stubbed/fake objects. I find them a lot less trouble and they are way better at keeping test code under control because it's not cluttered with all sorts of half baked implementations. They also help to clarify what is being tested.

Another advantage is that I only have to address where the class under test needs something specific from the mock. So I don't have to code where it's not important. As for verification, again I only have to very the calls from the class under test to the mock that I care about and consider important aspects of the test.

Ah, no not correct at all. Mock objects are not stubs/fakes. Fakes and stubs are different names for the same thing - An explicitly coded up extension of of a class for the purpose of testing either the class they extend, or injecting into some other class that is being tested to facilitate testing. They exist as an expressly written class in the test code. Mocks on the other hand, http://psyleb.org/showthread.php?p=35373#post35373 - http://psyleb.org/showthread.php?p=35373#post35373 , are dynamically created by mocking frameworks such as mockito. Mocks have a number of advantages over the stubs/fakes and are not as brittle. drekka May 11 '10 at 3:14

I think I see the miss-understanding. MF definitions are fine if you need to go to that level. I talking about the coding requirements. Dummys/Fakes/Stubs(DFSs) require coding an extra class. Mocks do not. That makes a fundamental difference to the test code and is a cause of much confusion amongst developers. I seen project teams refer to DFSs as mocks, and then get all confused when they try to introduce a mocking framework. The reason I disagreed was that you said to implement mocks and stubs. That, to me, indicated a miss-understanding of what mocks are. drekka May 11 '10 at 8:15

I think, the problem is always the same, although it comes in different flavours: If you have tests that somehow cover the internals of a class, then you will break the tests that cover this internal code.

IMHO there are two ways to deal with that:

Your tests only cover the public contract of a class - a test strategy which is widely adopted for that exact reason: You don't have to change your tests as long as the public contract remains constant, http://www.pandorahome.co.uk - pandora Sale . Unfortunately, this is not, http://www.weddingdress2013.co.uk - cheap wedding dresses , what you will have when doing Test-driven development.

If your tests come from a TDD process, then they will regularly cover non-public code. This means that they will break if you change the code. The only way to keep things in sync here is to 'fix' the tests together with the code. This means more maintenance during development. There's no recipe to easily deal with that (other than throw away the test, of course.).

My personal 'way out' is think in terms of 'code elements' rather than just code. A code element consists of three parts: Documentation, test, code. So if you change one part of the element, you have to also adjust the other two - otherwise you leave a broken code element behind.



Print Page | Close Window

Bulletin Board Software by Web Wiz Forums version 8.03 - http://www.webwizforums.com
Copyright ©2001-2006 Web Wiz Guide - http://www.webwizguide.info