Note that there are some explanatory texts on larger screens.

plurals
  1. POHow heavy I should test on a simple get property?
    primarykey
    data
    text
    <p>I am... kind of a beginner on unit testing. </p> <p>I just read some Unit Testing Best Practices. Kind of understand the unit test is meant to prevent changes made on code that will break the application. And we will want create test cases on all the object's public API(getter, methods) to test the object's behavior to see if is as we are expected.</p> <p>So now.. I have a little simple class I need to test:</p> <pre><code>public class Foo{ private readonly string _text; public Foo(string initialText) { this._text = initialText; } public string Text {get;} //Some other methods that will use this Text property to parsing, comparasion etc public string RichTextFormat {....} } </code></pre> <p>In here, this as in the comment, this <strong>Text</strong> property is use a lot of place for parsing, comparasion etc.</p> <p>So I think is very important to ensure the <strong>Text</strong> property returns exactly what I passed inside the constructor.</p> <p>Here is the test cases I wrote...</p> <pre><code>[TestMethod] public void Text_WhenInitialTextIsNull() { string initalizeText = null; Foo realFoo = new Foo(initalizeText); Assert.AreEqual(initalizeText, realFoo.Text); } [TestMethod] public void Text_WhenInitialTextIsEmpty() { string initalizeText = string.Empty; Foo realFoo = new Foo(initalizeText); Assert.AreEqual(initalizeText, realFoo.Text); } [TestMethod] public void Text_WhenInitialTextIsOneLetter() { string initalizeText = "A"; Foo realFoo = new Foo(initalizeText); Assert.AreEqual(initalizeText, realFoo.Text); } [TestMethod] public void Text_WhenInitialTextIsOneSpecialCharacter() { string initalizeText = "!"; Foo realFoo = new Foo(initalizeText); Assert.AreEqual(initalizeText, realFoo.Text); } [TestMethod] public void Text_WhenInitialTextIsOneSentense() { string initalizeText = "Hello, World!"; Foo realFoo = new Foo(initalizeText); Assert.AreEqual(initalizeText, realFoo.Text); } [TestMethod] public void Text_WhenInitialTextIsOneParagraph() { string initalizeText = "Who's the Smartphone Winner? " + System.Environment.NewLine + " On the smartphone front, however, iSuppli put Apple at number one," + " while Strategy Analytics pointed to Samsung. " + System.Environment.NewLine + " According to iSuppli, Apple shipped 35 million smartphones in the first quarter" + " to Samsung's 32 million. Strategy Analytics, however, said Samsung's total was" + " 44.5 million to Apple's 35.1 million. Nokia landed at number three on both lists" + " with 12 percent market share. "; Foo realFoo = new Foo(initalizeText); Assert.AreEqual(initalizeText, realFoo.Text); } </code></pre> <p>I wonder if this... is too heavy?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload