.net持续集成单元测试篇之单元测试简介以及在visual studio中配置Nunit使用环境
- 2019 年 10 月 3 日
- 筆記
?????????????
???????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???
• ??????????
• ??????
• ????????
• ?????????????
• ?????????
• ?????????
• ????????????
• ?????????????????
??????
?????????????,?????????????,?????????????,??????????????.????????????????????????,?????????.?????????
Should_Return(Throw)_Result(exception)_If(when)But
??Should????????,Return??Throw?????????????,If?????????????,But?????.
???????
????????????????????????????????????????????????????????????????????????????????
????????????
???????????????????????????????????????????????????????????????????????????????????
??????
??????
[????????????]
TDD????
????????????TDD????????????????????????????????????????????????????????????????
????????
???????????????????????????
Nunit????????
NUnit ????????.NET????Xunit????????????.NET?????????????????????????????.NET?????????????????
???????Java??????JUnit??????????NUnit?????????????????JUnit??????????????????????????????
???VS????????Nuget???????????????
?????visualStudio????Resharper??,?????????????????,???????????,????VisualStudio????????????,
????????VisualStudio???????.
??????????VisualStudio???????,?????Nunit.Console
?????????
?????????????????FirstUnitTest???
?????using NUnit.Framework;????Nunit
??????????????
??TestFixture?????????????,???????,???????????????
????Test????????????????,????Test??,????????????????????
????????????,???????????.
?????????
??VisualStudio??????????
????,??????Test(??)-Windows(??)-Test Explorer(?????)????VisualStudio????????,?????????,????Test Explorer?????????????(??????????FirstUnitTest)
??????,????Test Explorer?FirstUnitTest???????,??????
????Run Selected Test(?????????)????????????
????????Test Explorer??????
????????
???????????????????,?????????X ???????,????,????????? ??????,???????! ?????????(??????????????)
?????????????????????????? ,????,?????????.
????????
??????????????????????????,??????????,Test Explorer???????????????????
??????????????????????True,????False.???????????????,StackTrace???????????.
???-?????????:??????,???????,?????????,?????????????????,?????????,???????????????????,?????????????????????????????,?????????????????????????????,????????,????????????????Source???????,??????????????.
????????????????,??????????,??????????????????????????,???????F12,???????????
??????????????,????????????????,?????????????????????????????
??????
????????????????????,?????????3+4*5/2???0,???????????????????,???????????????,?????????????
?????????????????,???Test Explorer??????,??????,??????Debug Select Tests(??????)
????????????????,?????
?????????????????.
????????????,???????????????????,????VisualStudio?????????????,?????????????,?????.
??Resharper??????
Resharper?VisualStudio?????,???????,????????????.????VisualStudio????Resharper??,?????Resharper???????,??Resharper??????????VisualStudio?????????????.
?????Resharper,VisualStudio????????Resharper??,?????????????Resharper Unit Test Explorer
???VisualStudio Test Explorer??
????VisualStudio???Test Explorer????,????????FirstUnitTest?,????????
?????Run Unit Test????????,??Debug Unit Tests????????????,?VisualStudio???????????.
?????????Visual Studio???????????????,?????
??????????????????????,????????????????????????????
??????
?????????????????,????VisualStudio????????????????
????????????????????????.
??,????????,????????????????????,VisualStudio???????????Copy All??????,?????????,??????????????,?????.
???????,????????????
?????Text,XML?HTML,???xml?html??????,??????Text??,??Export to Text???????
?????????????????,???????????,????Copy to Clipborard?????????,??????????????????????
Resharper????-????
??????????,???????????????,????????????????,????????,????????????,?????????????,??????.????????????????(??????????),?????????????????????.??,?????????????????????.??????????????????????,????????????????,??????????,????????????????????????.(???????????DateTime.Now??Datetime.Now????????????????,??????????.)
?????????????????????????????,????????????????????????.
????????,???????????,?????????????????????,????????Resharper Unit Test Explorer?????????????????????.
???,???????????????,???Explorer????????????.
??????,?????????,?????????,????????????,???????????,???????????????????????????
Resharper????????????
?????????,???Test Explorer?????????????????????????,???Explorer??????????????,????????????????????????,
??????????????,?????Explorer(???Explorer???????Resharper Unit Test Explorer??VisualStudio Test Explorer,??windows explorer????)??,???????????,???????????????????.Resharper??????????????,????????????????,?????Explorer???????????.
????.???????Test??,Resharper?????,????????????????????????
???????????????
??Run???????.
?????????????????????????????
??????????????????????????????
???Run?Debug??????All?,??????????????????.