??????????????????
???????????? ???????[ 2014/1/10 16:06:53 ] ??????????????? ??????
???????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?????????????μ?о????????????Щ????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11