我目前正在对一个大学注册系统进行单元测试,而当我要测试的方法包含一个将与大学联系并担任调解员的调解员时,它总是会出错。有没有关于如何测试这种方法的想法?
方法是:
public void SelectCourse(List<Course> courses)
{
if (this.IsFullTime)
{
while (_CurrentCourses.Count < LEAST_NUM_OF_COURSES_FULLTIME)
{
Random rand = new Random();
byte[] b = new byte[1];
rand.NextBytes(b);
int i = rand.Next(courses.Count);
Course c = courses.ToArray()[i];
((University)mediator).RegisterStudentForCourse(this, c);
}
}
else
{
while (_CurrentCourses.Count < LEAST_NUM_OF_COURSES_PARTTIME)
{
Random rand = new Random();
byte[] b = new byte[1];
rand.NextBytes(b);
int i = rand.Next(courses.Count);
Course c = courses.ToArray()[i];
// I always //has unit test error with this line!!:
((University)mediator).RegisterStudentForCourse(this, c);
}
}
System.Console.WriteLine("Student: "
+ this.Name
+ ", with student number: ("
+ this.StudentNumber
+ ") registered.");
}