I'm ... new to unit testing.
I just read some guidelines for unit testing. It is clear that unit test is designed to prevent changes to the code that violates the application. And we will want to create test cases on all object public APIs (getter, methods) in order to check the behavior of the object to see what, as expected.
So, now .. I have a small class that I need to check:
public class Foo{
private readonly string _text;
public Foo(string initialText)
{
this._text = initialText;
}
public string Text {get;}
public string RichTextFormat {....}
}
Here, as in the commentary, this Text property uses a lot of space for parsing, comparison, etc.
Therefore, I consider it very important that the Text property returns what I passed inside the constructor.
, ...
[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 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 32 million. Strategy Analytics, however, said Samsung total was" +
" 44.5 million to Apple 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);
}
, ... ?