.net持续集成单元测试篇之单元测试简介以及在visual studio中配置Nunit使用环境

  • 2019 年 10 月 3 日
  • 筆記

????

?????????????

???????

???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

???

• ??????????

• ??????

• ????????

• ?????????????

• ?????????

• ?????????

• ????????????

• ?????????????????

??????

?????????????,?????????????,?????????????,??????????????.????????????????????????,?????????.?????????
Should_Return(Throw)_Result(exception)_If(when)But

??Should????????,Return??Throw?????????????,If?????????????,But?????.

???????

????????????????????????????????????????????????????????????????????????????????

????????????

???????????????????????????????????????????????????????????????????????????????????

Avatar

??????

??????

[????????????]

Avatar

TDD????

Avatar

????????????TDD????????????????????????????????????????????????????????????????

????????

???????????????????????????

Nunit????????

NUnit ????????.NET????Xunit????????????.NET?????????????????????????????.NET?????????????????
???????Java??????JUnit??????????NUnit?????????????????JUnit??????????????????????????????
???VS????????Nuget???????????????

Avatar
?????visualStudio????Resharper??,?????????????????,???????????,????VisualStudio????????????,
????????VisualStudio???????.
??????????VisualStudio???????,?????Nunit.Console

?????????

?????????????????FirstUnitTest???
?????using NUnit.Framework;????Nunit
??????????????
Avatar
??TestFixture?????????????,???????,???????????????
????Test????????????????,????Test??,????????????????????
????????????,???????????.

?????????

??VisualStudio??????????

Avatar
????,??????Test(??)-Windows(??)-Test Explorer(?????)????VisualStudio????????,?????????,????Test Explorer?????????????(??????????FirstUnitTest)
??????,????Test Explorer?FirstUnitTest???????,??????
Avatar
????Run Selected Test(?????????)????????????

Avatar

????????Test Explorer??????
????????
???????????????????,?????????X ???????,????,????????? ??????,???????! ?????????(??????????????)
?????????????????????????? ,????,?????????.

????????

??????????????????????????,??????????,Test Explorer???????????????????
Avatar
??????????????????????True,????False.???????????????,StackTrace???????????.

???-?????????:??????,???????,?????????,?????????????????,?????????,???????????????????,?????????????????????????????,?????????????????????????????,????????,????????????????Source???????,??????????????.
Avatar

????????????????,??????????,??????????????????????????,???????F12,???????????

Avatar

??????????????,????????????????,?????????????????????????????

Avatar

??????

????????????????????,?????????3+4*5/2???0,???????????????????,???????????????,?????????????
?????????????????,???Test Explorer??????,??????,??????Debug Select Tests(??????)

Avatar

????????????????,?????

Avatar
?????????????????.
????????????,???????????????????,????VisualStudio?????????????,?????????????,?????.

??Resharper??????

Resharper?VisualStudio?????,???????,????????????.????VisualStudio????Resharper??,?????Resharper???????,??Resharper??????????VisualStudio?????????????.
?????Resharper,VisualStudio????????Resharper??,?????????????Resharper Unit Test Explorer

Avatar

???VisualStudio Test Explorer??

Avatar

????VisualStudio???Test Explorer????,????????FirstUnitTest?,????????

Avatar

?????Run Unit Test????????,??Debug Unit Tests????????????,?VisualStudio???????????.

Avatar

?????????Visual Studio???????????????,?????
??????????????????????,????????????????????????????

Avatar

??????

Avatar

?????????????????,????VisualStudio????????????????

Avatar

????????????????????????.
??,????????,????????????????????,VisualStudio???????????Copy All??????,?????????,??????????????,?????.
???????,????????????

Avatar

?????Text,XML?HTML,???xml?html??????,??????Text??,??Export to Text???????

Avatar

?????????????????,???????????,????Copy to Clipborard?????????,??????????????????????

Resharper????-????

??????????,???????????????,????????????????,????????,????????????,?????????????,??????.????????????????(??????????),?????????????????????.??,?????????????????????.??????????????????????,????????????????,??????????,????????????????????????.(???????????DateTime.Now??Datetime.Now????????????????,??????????.)
?????????????????????????????,????????????????????????.

????????,???????????,?????????????????????,????????Resharper Unit Test Explorer?????????????????????.

Avatar

???,???????????????,???Explorer????????????.
??????,?????????,?????????,????????????,???????????,???????????????????????????

Avatar

Resharper????????????

?????????,???Test Explorer?????????????????????????,???Explorer??????????????,????????????????????????,
??????????????,?????Explorer(???Explorer???????Resharper Unit Test Explorer??VisualStudio Test Explorer,??windows explorer????)??,???????????,???????????????????.Resharper??????????????,????????????????,?????Explorer???????????.

Avatar

????.???????Test??,Resharper?????,????????????????????????
???????????????

Avatar

??Run???????.

Avatar

?????????????????????????????

??????????????????????????????

Avatar

???Run?Debug??????All?,??????????????????.