Donaldson, John (GEO | 7 Jul 2011 18:03
Picon
Favicon

RE: Duplicate constants

Arnon,

Usually, when I am testing a complex returned string, I'll test for "contains" and not "is equal".
This gets you a bit less fragility, and lets you modify some aspects that you may not be interested in
enforcing such as grammar and layout. Of course, if you are interested in enforcing the exact string, then
you'll have to do that.

John D.

-----Original Message-----
From: testdrivendevelopment <at> yahoogroups.com [mailto:testdrivendevelopment <at> yahoogroups.com] On
Behalf Of arnonaxelrod
Sent: 07 July 2011 13:17
To: testdrivendevelopment <at> yahoogroups.com
Subject: [TDD] Duplicate constants

Hi,

Here's another question I often have doubts about:

Suppose I have to write a method that returns a string, which should be
defined internally in the application (not entered by the user). So when
I first write the test I write this string inside the test. For example:

var result = MyMethod();

Assert.AreEqual("This is a constant string", result);

And then when I implement MyMethod() I write the exact same string
inside that method. The problem with that is that the string is
duplicated between the test and the production code. From one hand, I
don't see a simple way to implement this method with TDD without this
duplication, but on the other hand, I don't see much value in having to
update the string twice in if the I want to change the string.

This problem is very common in tests that verify the messages of
exceptions.

Another "twist" to this question is what happens if the string is
composed with parameters (e.g. using string.Format). In this case the
entire string.Format expression has to be duplicated.

Is this kind of duplications between test and production code normal in
TDD, or am I doing something wrong?

Thanks,

Arnon.

[Non-text portions of this message have been removed]

------------------------------------

Yahoo! Groups Links

------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/testdrivendevelopment/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/testdrivendevelopment/join
    (Yahoo! ID required)

<*> To change settings via email:
    testdrivendevelopment-digest <at> yahoogroups.com 
    testdrivendevelopment-fullfeatured <at> yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    testdrivendevelopment-unsubscribe <at> yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Gmane