前提・実現したいこと
Visual Studio 2015 Proの内蔵MSTestでテストを書いています。
テストの書き方「いろは」の「ろ」を教えてください。
C#
1 public static bool IsNumber(string text) 2 { 3 if (text == null) return false; 4 else if (Regex.Match(text, "^[0-9]+$").Success) return true; 5 else return false; 6 }
があるとき、
C#
1 [TestMethod()] 2 public void IsNumberTest1() 3 { 4 string text = "012"; 5 Assert.AreEqual(true, Validation.IsNumber(text)); 6 } 7 8 [TestMethod()] 9 public void IsNumberTest2() 10 { 11 string text = "012a"; 12 Assert.AreEqual(false, Validation.IsNumber(text)); 13 } 14 15 [TestMethod()] 16 public void IsNumberTest3() 17 { 18 string text = "abc"; 19 Assert.AreEqual(false, Validation.IsNumber(text)); 20 }
をテストしました。
returnがあるときは、expectedに予定する値を入れればよいのですが、returnがvoidのとき、たとえば下記のMethodをTestするにはどういうテストコードを書けばよいですか?
static string BaseText = string.Empty; public static void SetText(string text) { BaseText = text; }
補足情報(FW/ツールのバージョンなど)
Visual Studio 2015 Pro
回答5件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/02 02:41
2018/03/02 02:47 編集
2018/03/02 02:52
2018/03/02 02:54
2018/03/02 02:56
2018/03/02 03:00
2018/03/02 03:08 編集
2018/03/02 04:01
2018/03/02 04:10