About TDD Constructor (from maillist)

Source: Internet
Author: User

Frank:

Hi everyone, I wonder if anyone can help me with this. (I am a newbie in this list. If my problem is inappropriate, please forgive me .)

In shortTest-firstHow should we handle enumeration variables?

Since we should not meetRed TestWrite anyCode, What should I do in the following example?

Drink drink = new drink (drinktype. Cocktail );

Next, I should write the test and verification constructor:

[Test]
Public void test_constructor ()
{
Drink d = new drink (drinktype. Cocktail );
Assert. isnotnull (d );
}

However, should I write a test to test this enumeration parameter? What should I do?

Charlie:

You seem to have done something too fast. In fact, if it is me, I will first write a constructor like this:

Drink d = new drink ();

Of course, after a while, I may want to know the type of the drink, so I will write a test:

Assert. areequal ("Cocktail", D. drinktype );OrAssert. areequal (drinktype. Cocktail, D. drinktype );

This test obviously cannot pass compilation. I will write a little bit of code to let it pass:

Public String drinktype
{
Get {return "Cocktail ";}
}

The constructor is needed only when I encounter a new type of beverage.

As for testing the enumeration type, the enumeration type is only a declaration and does not contain real code. Therefore, you do not need to test it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.