???????nUnit???????
?????????????????????????????????????????в????ι??????????……?????й???????У??????????????
????????????????????????????????????????????????
????????????????????????????????????????ò????????????????? 1. ???????????---????????2. ????????????????е?---????????
??????????:
[TestFixture]
public class when_create_an_exam
{
[Test]
public void it_should_assign_parameters_to_properties()
{
//Arrange
var stub_exam_def = new ExamDef("98");
var stub_district = new District("01");
var stub_date = new Date(2011?? 1?? 1);
//Action
var subject = new Exam(stub_district?? stub_exam_def?? stub_date);
//Assert
Assert.AreEqual(stub_district??subject.District);
Assert.AreEqual(stub_exam_def??subject.ExamDef);
Assert.AreEqual(stub_date??subject.Date);
}
}
?????????????м???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Stub??????????????DDD????????????????????????????????ж??????????????????????????OK?????!
??????ζ????---????????
????????????????????????????β????????ЩСС?????????????????и?????????????????????????????и????????????????????????????????????????????????????????????????????ЩСС??????????????
?????????????????????
????1. ????????????:???????????????????????(????????)???????????????????????????????????????????????飬?????????????????
????2. ??????????????????????????????????---???????????????Exam?????ExamDef?? District??????????????
????3. ??????????????????????????У?????????????????????????????????????????????????????y?????
???????????????????????????????????????????3???????????????????“???????”??
????MSpec??????--- AAA??
?????????????????????????????????????????Щ?????????????????????????????????????????bug?????????????????????????????????д???????
?????????????????????????????????????nUnit??????????????????γ????????????????????????鷳???????????MSpec???????????????и????????AAA?????????Arrange??Action??Assert??3A?????????!
??????MSpec???????????????????Establish?? Because?? It??????????????????????????????????
??????????:
public class When_create_an_exam_by
{
private Establish context =
() =>
{
stub_exam_def = new ExamDef("98");
stub_district = new District("01");
stub_date = new Date(2011?? 1?? 1);
};
private Because of =
() => subject = new Exam(stub_district?? stub_exam_def?? stub_date);
private It should_assign_to_properties =
() =>
{
subject.District.ShouldEqual(stub_district);
subject.ExamDef.ShouldEqual(stub_exam_def);
subject.Date.ShouldEqual(stub_date);
};
private static ExamDef stub_exam_def;
private static District stub_district;
private static Date stub_date;
private static Exam subject;
}
?????????????????е???????????????????????
?????????:

??????nUnit??????MSpec?????????????μ?о????????????Щ????????????????????????????????