測試在這裏,他們是非常重複,我想改變...單元測試的重複問題
[TestClass]
public class CompareDataTest
{
private void GenerateTerms(int firstTerm, int secondTerm, out TaughtUnit firstGrade, out TaughtUnit secondGrade)
{
firstGrade = new TaughtUnit("foo");
secondGrade = new TaughtUnit("bar");
}
[TestMethod]
public void CompareResultsTest1()
{
var firstGrade = new TaughtUnit("foo");
firstGrade.Percentage.Add("GRADE", 38);
var secondGrade = new TaughtUnit("foo");
secondGrade.Percentage.Add("GRADE", 70);
var oldTerm = new List<TaughtUnit>() { firstGrade };
var newTerm = new List<TaughtUnit>() { secondGrade };
var rankBefore = firstGrade.Percentage;
var rankNow = secondGrade.Percentage;
var messages = Program.CompareData(oldTerm, newTerm);
Assert.AreEqual(0, messages.Count);
}
[TestMethod]
public void CompareResultsTest2()
{
var firstGrade = new TaughtUnit("foo");
firstGrade.Percentage.Add("GRADE", 0);
var secondGrade = new TaughtUnit("foo");
secondGrade.Percentage.Add("GRADE", 35);
var oldTerm = new List<TaughtUnit>() { firstGrade };
var newTerm = new List<TaughtUnit>() { secondGrade };
var rankBefore = firstGrade.Percentage;
var rankNow = secondGrade.Percentage;
int gradeOld = 0; int gradeNew = 10;
var getGradeOld = firstGrade.Percentage.TryGetValue("GRADE", out gradeOld);
var getGradeNew = secondGrade.Percentage.TryGetValue("GRADE", out gradeNew);
var difference = gradeNew - gradeOld;
var messages = Program.CompareData(oldTerm, newTerm);
Assert.AreEqual(1, messages.Count);
Assert.AreEqual("foo: GRADE rank has dropped by 30", messages[0]);
}
我想我這組測試前,應使用私人無效,但我不知道如何... 我如何參考私人空間中創建的內容?