{"id":2508,"date":"2021-10-11T00:41:04","date_gmt":"2021-10-10T16:41:04","guid":{"rendered":"https:\/\/www.develop-note.com\/blog\/?p=2508"},"modified":"2022-02-16T17:21:00","modified_gmt":"2022-02-16T09:21:00","slug":"mstest-specflow","status":"publish","type":"post","link":"https:\/\/www.develop-note.com\/blog\/2021\/10\/11\/mstest-specflow\/","title":{"rendered":"D-04-\u958b\u59cb\u6e2c\u8a66 ? mstest ? specflow"},"content":{"rendered":"<h1>\u64b0\u5beb\u6e2c\u8a66<\/h1>\n<p>\u76f8\u4fe1\u5f88\u591a\u4eba\u6703\u60f3\u8981\u589e\u52a0\u7cfb\u7d71\u7684\u7a69\u5b9a\u5ea6\uff0c\u4f46\u662f\u9019\u8a72\u5982\u4f55\u505a\u5247\u662f\u500b\u554f\u984c\uff0c\u76f8\u4fe1\u5f88\u591a\u4eba\u770b\u904e<a href=\"https:\/\/dotblogs.com.tw\/hatelove\/2013\/01\/11\/learning-tdd-in-30-days-catalog-and-reference\" title=\"91 TDD\" rel=\"nofollow noopener\" target=\"_blank\">91 TDD<\/a>\u7684\u6587\u7ae0\uff0c\u4e5f\u76f8\u4fe1\u5e0c\u671b\u80fd\u5f9e\u55ae\u5143\u6e2c\u8a66\u589e\u52a0\u7cfb\u7d71\u7684\u7a69\u5b9a\u5ea6\u4ee5\u53ca\u6b63\u78ba\u6027\uff0c\u4e0d\u904e\u5728dotnetcore\u5167\u8981\u5982\u4f55\u5beb\u6e2c\u8a66\u6848\u4f8b\u5462\uff0c\u4eca\u5929\u5c31\u8b93\u6211\u5011\u4f86\u7814\u7a76\u4e00\u4e0bvscode\u600e\u9ebc\u7528specflow\u4f86\u5beb\u6e2c\u8a66\u6848\u4f8b\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u6e2c\u8a66\u6848\u4f8b<\/h2>\n<p>\u300c\u524d\u8f29\uff0c\u70ba\u4ec0\u9ebc\u6211\u5011\u5e38\u5e38\u6703\u5beb\u51fa\u5f88\u591abug\u300d<br \/>\n\u4eca\u5929\u5c0f\u5149\u8ddf\u5927\u982d\u8acb\u6559\u600e\u9ebc\u589e\u52a0\u7a0b\u5f0f\u7a69\u5b9a\u5ea6\u53ca\u6b63\u78ba\u6027\u7684\u554f\u984c\uff0c\u4e0d\u904e\u807d\u5230\u9019\u554f\u984c\u5f8c\u5927\u982d\u4e5f\u53ea\u662f\u6b6a\u8457\u982d\u601d\u8003\u8457\uff0c\u4e5f\u6c92\u6709\u6b63\u9762\u56de\u61c9\u5c0f\u5149\u7684\u7591\u554f\u3002<br \/>\n\u300c\u5176\u5be6\u9019\u4e5f\u662f\u82e6\u60f1\u6211\u597d\u4e45\u7684\u554f\u984c\u300d<br \/>\n\u300c\u9084\u662f\u6211\u5011\u5169\u500b\u4e00\u8d77\u53bb\u554f\u8001K\u524d\u8f29\u5462\u300d<br \/>\n\u300c\u9019\u597d\u50cf\u662f\u4e0d\u932f\u7684\u89e3\u6c7a\u65b9\u5f0f\u3002\u300d<br \/>\n\u6240\u4ee5\u4ed6\u5011\u5169\u500b\u5c31\u4e00\u8d77\u4f86\u5c0b\u554f\u8001K\u8a72\u5982\u4f55\u8655\u7406\u9019\u554f\u984c\uff0c\u4e0d\u904e\u7576\u4ed6\u5011\u554f\u8001K\u4e4b\u5f8c\u78ba\u5f97\u5230\u9019\u6a23\u7684\u7b54\u6848\u3002<br \/>\n\u300c\u9019\u554f\u984c\u53ef\u80fd\u53ea\u80fd\u554f\u4e0a\u5e1d\u4e86\uff0c\u56e0\u70ba\u4eba\u975e\u8056\u8ce2\u5b70\u80fd\u7121\u904e\u3002\u300d<br \/>\n\u807d\u4e86\u9019\u500b\u7b54\u6848\u5f8c\u5169\u500b\u4eba\u90fd\u5012\u62bd\u4e86\u4e00\u53e3\u6c23\uff0c\u800c\u4e14\u6574\u500b\u50cf\u662f\u6d29\u6c23\u7684\u76ae\u7403\uff0c\u4e0d\u904e\u5927\u982d\u7acb\u523b\u610f\u6703\u5230\u4ed6\u5011\u554f\u932f\u554f\u984c\u4e86\uff0c\u6240\u4ee5\u5927\u982d\u53c8\u63db\u500b\u65b9\u5f0f\u554f\u4e86\u4e00\u6b21\u3002<br \/>\n\u300c\u524d\u8f29\uff0c\u6211\u5011\u8a72\u5982\u4f55\u6e1b\u5c11bug\u7684\u7522\u751f\u5462\u3002\u300d<br \/>\n\u807d\u4e86\u5927\u982d\u554f\u7684\u554f\u984c\u5f8c\u8001K\u54c8\u54c8\u5927\u7b11\uff0c\u4e26\u4e14\u9019\u9ebc\u8aaa\u3002<br \/>\n\u300c\u5b7a\u5b50\u53ef\u6559\u4e5f\uff0c\u6211\u5011\u6c92\u8fa6\u6cd5\u4e0d\u5beb\u51fabug\uff0c\u4f46\u662f\u6211\u5011\u80fd\u60f3\u8fa6\u6cd5\u6e1b\u5c11\u5beb\u51fabug\u7684\u72c0\u6cc1\uff0c\u4ee5\u53ca\u6aa2\u67e5\u6709\u6c92\u6709\u5beb\u51fabug\u3002\u300d<br \/>\n\u8aaa\u5b8c\u4e86\u9019\u53e5\u8a71\u5f8c\u8001K\u559d\u4e86\u676f\u6c34\uff0c\u4e26\u4e14\u8d77\u8eab\u8d70\u4e86\u5e7e\u6b65\u5f8c\u793a\u610f\u5927\u982d\u8ddf\u5c0f\u5149\u8ddf\u4e0a\u4f86\u3002\u6240\u4ee5\u5c0f\u5149\u8ddf\u5927\u982d\u5c31\u8ddf\u8457\u8001K\u5f80\u8fa6\u516c\u5ba4\u5916\u9762\u8d70\u53bb\u3002\u8d70\u5230\u5916\u9762\u516c\u5712\u5f8c\u8001K\u958b\u59cb\u8aaa\u8d77\u4f86\u4e86\u3002<br \/>\n\u300c\u7cfb\u7d71\u3001\u9700\u6c42\u8ddf\u7a0b\u5f0f\u90fd\u662f\u4eba\u8a2d\u8a08\u7684\uff0c\u6240\u4ee5\u4f9d\u64da\u7406\u89e3\u529b\u53ca\u7d30\u5fc3\u7a0b\u5ea6\u4e0d\u540c\u6240\u505a\u51fa\u4f86\u7684\u6771\u897f\u5b8c\u6210\u5ea6\u4e5f\u6703\u4e0d\u540c\u3002\u300d<br \/>\n\u9019\u6642\u8001K\u8d70\u5230\u6a39\u4e0b\u7684\u5ea7\u6905\u4e0a\u5750\u4e86\u4e0b\u4f86\uff0c\u4e26\u4e14\u7e7c\u7e8c\u8aaa\u3002<br \/>\n\u300c\u4e0d\u904e\u9084\u662f\u53ef\u4ee5\u900f\u904e\u4eba\u8207\u4eba\u4e4b\u9593\u7684\u914d\u5408\u4f86\u6aa2\u9a57\u51fa\u7cfb\u7d71\u6709\u6c92\u6709\u554f\u984c\uff0c\u6240\u4ee5\u9019\u6642\u9664\u4e86\u6574\u5408\u6e2c\u8a66\u4e4b\u5916\u4e5f\u53ef\u4ee5\u900f\u904e\u55ae\u5143\u6e2c\u8a66\u53ca\u65e9\u77e5\u9053\u5143\u4ef6\u7684\u6b63\u78ba\u6027\u3002\u300d<br \/>\n\u8aaa\u5230\u9019\u88e1\u5927\u982d\u4f3c\u4e4e\u6709\u9ede\u7591\u554f\uff0c\u6240\u4ee5\u554f\u4e86\u4e00\u500b\u554f\u984c\u3002<br \/>\n\u300c\u4f46\u662f\u8981\u600e\u9ebc\u8b93QA\u6216\u662f\u4f01\u5283\u4f86\u914d\u5408\u6aa2\u9a57\u7cfb\u7d71\u5462\uff0c\u4e00\u5b9a\u8981\u7b49\u5230\u7cfb\u7d71\u5b8c\u6210\u5f8c\u518d\u4f86\u6aa2\u9a57\u55ce\uff1f\u300d<br \/>\n\u9019\u6642\u8001K\u9ede\u9ede\u982d\uff0c\u56e0\u70ba\u5927\u982d\u554f\u4e86\u4e00\u500b\u597d\u554f\u984c\u3002<br \/>\n\u300c\u9019\u6642\u53ef\u4ee5RD\u8ddfQA\u9084\u6709\u4f01\u5283\u4e00\u8d77\u9032\u884cBDD\u300d<\/p>\n<h3>BDD<\/h3>\n<p>\u6240\u4ee5\u91cd\u9ede\u4f86\u4e86\uff0c\u4ec0\u9ebc\u662f<a href=\"https:\/\/en.wikipedia.org\/wiki\/Behavior-driven_development\" title=\"BDD\" rel=\"nofollow noopener\" target=\"_blank\">BDD<\/a>\u5462\uff0cBDD\u662f<code>Behavior-driven development<\/code>\u7684\u7c21\u7a31\uff0c\u4ed6\u9f13\u52f5RD\u8ddfQA\u9084\u6709\u975e\u6280\u8853\u4eba\u54e1\u5354\u4f5c\u958b\u767c\uff0c\u4e0d\u904e\u9019\u600e\u9ebc\u505a\u5230\uff0c\u975e\u6280\u8853\u4eba\u54e1\u5c0d\u65bc\u7a0b\u5f0f\u78bc\u7684\u64b0\u5beb\u61c9\u8a72\u4e0d\u6e05\u695a\u3002\u6240\u4ee5\u9019\u6642\u5019\u5c31\u662f\u8b93\u975e\u6280\u8853\u4eba\u54e1\u900f\u904e\u81ea\u7136\u8a9e\u8a00\u5beb\u51fa\u6e2c\u8a66\u6848\u4f8b\uff0c\u4e26\u4e14\u8aaa\u660e\u5176\u91cd\u9ede\u6240\u5728\uff0c\u5982\u6b64\u7a0b\u5f0f\u958b\u767c\u4eba\u54e1\u53ef\u4ee5\u66f4\u8457\u91cd\u65bc\u7cfb\u7d71\u7684\u958b\u767c\u4ee5\u7b26\u5408\u6e2c\u8a66\u6848\u4f8b\u7684\u6aa2\u9a57\u3002\u9019\u6a23\u53ef\u4ee5\u5927\u5927\u7684\u6e1b\u5c11\u7a0b\u5f0f\u4eba\u54e1\u8207\u975e\u6280\u8853\u4eba\u54e1\u4e4b\u9593\u7684\u6e9d\u901a\u6210\u672c\uff0c\u9664\u6b64\u4e4b\u5916\u4e5f\u53ef\u4ee5\u6709\u4e00\u4efd\u7a0b\u5f0f\u7684\u8aaa\u660e\u6587\u4ef6\u53ef\u4ee5\u63d0\u4f9b\u7d66\u76f8\u95dc\u4eba\u54e1\u4e86\u89e3\u5167\u5bb9\u3002<\/p>\n<h4>BDD \u5982\u4f55\u64b0\u5beb<\/h4>\n<p>\u6240\u4ee5\u8981\u600e\u9ebc\u64b0\u5beb\u624d\u53ef\u4ee5\u8b93\u4eba\u4e86\u89e3\u7a0b\u5f0f\u7684\u4f5c\u7528\u4ee5\u53ca\u5176\u50f9\u503c\u5462\uff0c\u56e0\u6b64\u8981\u9075\u5faa\u4e00\u500b\u5927\u5bb6\u516c\u8a8d\u7684\u898f\u5247\u4f86\u5beb\u9019\u4efd\u6587\u4ef6\uff0c\u6240\u4ee5\u5c31BDD\u7684\u7bc4\u4f8b\u4f86\u8aaa\u9019\u4efd\u6587\u4ef6\u8981\u5305\u542b\u4e0b\u5217\u5167\u5bb9\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u6bb5\u843d<\/th>\n<th>\u5167\u5bb9\u8aaa\u660e<\/th>\n<th>\u5305\u542b\u8cc7\u8a0a<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Title<\/td>\n<td>\u8aaa\u660e\u6b64\u7a0b\u5f0f\u7684\u5546\u696d\u50f9\u503c<\/td>\n<td>\u7c21\u8ff0\u9019\u6bb5\u7a0b\u5f0f\u505a\u4ec0\u9ebc\u7684<\/td>\n<\/tr>\n<tr>\n<td>Narrative<\/td>\n<td>\u7c21\u77ed\u7684\u4ecb\u7d39\u9019\u7ae0\u7bc0<\/td>\n<td>As a \u67d0\u7a2e\u8eab\u4efd I want \u505a\u67d0\u4ef6\u4e8b\u60c5 so that \u6703\u5f97\u5230\u4ec0\u9ebc\u7d50\u679c<\/td>\n<\/tr>\n<tr>\n<td>Acceptance criteria<\/td>\n<td>\u8aaa\u660e\u60c5\u5883\u4ee5\u53ca\u5982\u4f55\u61c9\u5c0d<\/td>\n<td>Scenario Given And When Then<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>specflow<\/h3>\n<p>\u8aaa\u4e86\u90a3\u9ebc\u591aBDD\u5f97\u6982\u5ff5\uff0c\u4e0d\u904e\u5982\u4f55\u628a\u7a0b\u5f0f\u958b\u767c\u8ddfBDD\u548c\u5728\u4e00\u8d77\u5462\uff0c\u9019\u6642\u6211\u5011\u5c31\u9700\u8981\u4e00\u500b<a href=\"https:\/\/docs.specflow.org\/\" title=\"Specflow\" rel=\"nofollow noopener\" target=\"_blank\">Specflow<\/a>\u7684\u5de5\u5177\uff0c\u9019\u5de5\u5177\u5c31\u662f\u5e6b\u6211\u5011\u525b\u525b\u8aaa\u7684BDD\u6240\u5beb\u4e0b\u4f86\u7684\u81ea\u7136\u8a9e\u8a00\u7522\u751f\u7a0b\u5f0f\u7d50\u69cb\uff0c\u900f\u904e\u5be6\u4f5c<code>Step<\/code>\u4f86\u9054\u6210\u6e2c\u8a66\u6211\u5011\u7a0b\u5f0f\u6b63\u78ba\u6027\u7684\u5de5\u5177\u3002\u5728Visual Studio\u8ddfRider\u6709\u8f03\u597d\u7684\u652f\u63f4\uff0c\u4e0d\u904e\u6211\u5011\u76ee\u524d\u4f7f\u7528\u7684\u662fVSCode\uff0c\u6240\u4ee5\u4eca\u5929\u5c31\u4f86\u8a8d\u8b58\u5982\u4f55\u7528VSCode\u4f86\u64b0\u5beb\u6e2c\u8a66\u6848\u4f8b\u4ee5\u53ca\u9a57\u8b49\u7a0b\u5f0f\u7684\u6b63\u78ba\u6027\u3002<\/p>\n<h4>\u74b0\u5883\u8a2d\u5b9a<\/h4>\n<p>\u9019\u88e1\u6211\u5011\u9700\u8981\u7522\u751f\u4e00\u500b\u65b0\u7684\u5c08\u6848\uff0c\u4f46\u662f\u5728\u7522\u751f\u5c08\u6848\u4e4b\u524d\u8981\u5148\u5b89\u88dd\u4e9b\u6771\u897f\uff0c\u6240\u4ee5\u5148\u8981\u5b8c\u6210\u7684\u662f\u74b0\u5883\u8a2d\u5b9a\uff0c\u9019\u908a\u5148\u53c3\u8003<a href=\"https:\/\/docs.specflow.org\/projects\/specflow\/en\/latest\/vscode\/vscode-specflow.html\" title=\"\u5b89\u88ddSpecflow\" rel=\"nofollow noopener\" target=\"_blank\">\u5b89\u88ddSpecflow<\/a>\u7684\u5167\u5bb9\u4f86\u5b89\u88ddVSCode\u7684\u64f4\u5145\u5143\u4ef6<a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=salbert.awesome-dotnetcore-pack\" title=\"Awesome DotNetCore Pack\" rel=\"nofollow noopener\" target=\"_blank\">Awesome DotNetCore Pack<\/a>\u53ca<a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=alexkrechik.cucumberautocomplete\" title=\"Cucumber (Gherkin) Full Support\" rel=\"nofollow noopener\" target=\"_blank\">Cucumber (Gherkin) Full Support<\/a>\u3002\u5728\u5b89\u88dd\u5b8c\u6210\u5f8c\u518d\u8a2d\u5b9a\u6a94\u6307\u5b9aSpecflow\u4e2d\u653e\u7f6eStep\u7684\u7a0b\u5f0f\u78bc\u7684\u8cc7\u6599\u593e\u4ee5\u53ca\u6a94\u6848\u540d\u7a31\u7684\u6a21\u5f0f\uff0c\u8def\u5f91\u70ba\u6a94\u6848-&gt;\u559c\u597d\u8a2d\u5b9a-&gt;\u8a2d\u5b9a\u5f8c\u5728\u641c\u5c0b\u6b04\u7be9\u9078<code>Cucumber<\/code>\u4e4b\u5f8c\u627e\u5230<code>Cucumberautocomplete.Steps<\/code>\u6309\u4e0b\u7de8\u8f2f\u5f8c\u8f38\u5165\u4ee5\u4e0b\u5167\u5bb9\u3002<\/p>\n<pre><code class=\"language-json\">&quot;cucumberautocomplete.steps&quot;: [&quot;\/**\/Steps\/**\/*.cs&quot;]<\/code><\/pre>\n<p>\u9019\u6a23\u8a2d\u5b9a\u5b8c\u4e4b\u5f8c\u6211\u5011\u53ef\u4ee5\u5728feature\u6a94\u6848\u4e0a\u900f\u904e<code>ctrl+click<\/code>\u7acb\u523b\u9023\u7d50\u5230Step\u7684\u7a0b\u5f0f\u78bc\u4e0a\uff0c\u5982\u6b64VSCode\u7684\u8a2d\u5b9a\u544a\u4e00\u6bb5\u843d\u3002\u4e0d\u904e\u8981\u91cd\u982d\u5bebfeature\u662f\u4e00\u4ef6\u9ebb\u7169\u7684\u4e8b\uff0c\u800c\u4e14\u5efa\u7acb\u7a7a\u5c08\u6848\u4e5f\u662f\u4e00\u6a23\uff0c\u6240\u4ee5\u63a5\u4e0b\u4f86\u8981\u91dd\u5c0ddotnet cli\u52a0\u4ee5\u8a2d\u5b9a\uff0c\u9019\u908a\u53c3\u8003<a href=\"https:\/\/docs.specflow.org\/projects\/specflow\/en\/latest\/Installation\/Project-and-Item-Templates.html#net-cli-templates\" title=\"\u65b0\u589eSpecflow\u7bc4\u672c\" rel=\"nofollow noopener\" target=\"_blank\">\u65b0\u589eSpecflow\u7bc4\u672c<\/a>\u7684\u6b65\u9a5f\u4f86\u65b0\u589especflow\u7684\u7bc4\u672c\u3002\u6240\u4ee5\u9996\u5148\u5148\u5728\u547d\u4ee4\u5217\u8f38\u5165\u4ee5\u4e0b\u5167\u5bb9\u3002<\/p>\n<pre><code class=\"language-bash\">dotnet new -i SpecFlow.Templates.DotNet<\/code><\/pre>\n<p>\u900f\u904e\u4e0a\u8ff0\u6307\u4ee4\u53ef\u4ee5\u65b0\u589eSpecflow\u7684\u7bc4\u672c\u5230donet cli\u5167\uff0c\u7576\u65b0\u589e\u5b8c\u4e4b\u5f8c\u6211\u5011\u5c31\u53ef\u4ee5\u4f7f\u7528\u7bc4\u672c\u4f86\u7522\u751f\u5c08\u6848\u4ee5\u53cafeature\u7bc4\u672c\uff0c\u6240\u4ee5\u6211\u5011\u5148\u7522\u751f\u4e00\u500b\u7a7a\u7684\u5c08\u6848\u3002<\/p>\n<pre><code class=\"language-bash\">dotnet new specflowproject --unittestprovider mstest --framework net5.0 -o Tests<\/code><\/pre>\n<p>\u5982\u6b64\u6211\u5011\u5c31\u53ef\u4ee5\u7522\u751f\u4e00\u500b\u7a7a\u7684specflow\u7684\u5c08\u6848\uff0c\u63a5\u4e0b\u4f86\u6211\u5011\u53ef\u4ee5\u7522\u751f\u4e00\u500b\u7a7a\u7684\u51fd\u5f0f\u5eab\u53ea\u8981\u8f38\u5165\u4e00\u4e0b\u5167\u5bb9\u3002<\/p>\n<pre><code class=\"language-bash\">dotnet new classlib --framework net5.0 -o Libs<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\u518d\u5c07\u76f8\u4f9d\u7684\u5957\u4ef6\u90fd\u5148\u52a0\u5165\u9032\u4f86\uff0c\u8f38\u5165\u4ee5\u4e0b\u6307\u4ee4\u3002<\/p>\n<pre><code class=\"language-bash\">dotnet add package MSTest.TestFramework -v 2.2.7\ndotnet add package MSTest.TestAdapter -v2.2.7<\/code><\/pre>\n<p>\u7576\u7a7a\u5c08\u6848\u7522\u751f\u597d\u4e86\u4e4b\u5f8c\uff0c\u9019\u6642\u53ea\u8981\u5728\u6e2c\u8a66\u5c08\u6848\u4e2d\u53c3\u8003\u51fd\u5f0f\u5eab\u5c31\u53ef\u4ee5\u91dd\u5c0d\u51fd\u5f0f\u5eab\u7684\u5167\u5bb9\u64b0\u5beb\u6e2c\u8a66\u6848\u4f8b\u4e86\uff0c\u9019\u88e1\u53c3\u8003\u7684\u6307\u4ee4\u5982\u4e0b\u3002<\/p>\n<pre><code class=\"language-bash\">dotnet add reference ..\/Libs\/Libs.csproj<\/code><\/pre>\n<p>\u6240\u4ee5\u5148\u5728\u51fd\u5f0f\u5eab\u4e2d\u5beb\u4e00\u500b\u8981\u6e2c\u8a66\u7684\u65b9\u6cd5\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre><code class=\"language-cs\">public class Calculator\n{\n    public int Add(int first, int second)\n    {\n        return 0;\n    }\n}<\/code><\/pre>\n<p>\u6240\u4ee5\u63a5\u4e0b\u4f86\u6211\u5011\u8981\u958b\u59cb\u5beb\u6e2c\u8a66\u6848\u4f8b\u4e86\u3002<\/p>\n<h4>\u6e2c\u8a66\u6848\u4f8b\u64b0\u5beb<\/h4>\n<p>\u5982\u679c\u900f\u904e\u524d\u9762\u7684\u6b65\u9a5f\u7522\u751fspecflow\u5c08\u6848\u7684\u8a71\u6211\u5011\u61c9\u8a72\u53ef\u4ee5\u770b\u5230\u5167\u90e8\u5df2\u7d93\u6709\u4e9b\u4e9b\u7bc4\u4f8b\u6a94\u6848\u4e86\uff0c\u4f8b\u5982<code>Calculator.feature<\/code>\uff0c\u6211\u5011\u5c31\u4ee5\u9019\u6a94\u6848\u4f86\u958b\u59cb\u8aaa\u660e\u3002<\/p>\n<pre><code class=\"language-gherkin\">Feature: Calculator # \u8868\u982d\uff0c\u4ee5\u4e0b\u8aaa\u660e\u8a72\u7a0b\u5f0f\u7684\u529f\u7528\uff0cFeature: \u5f8c\u9762\u63a5\u7684\u53ef\u4ee5\u7528\u4f86\u8a2d\u5b9a\u7279\u5b9aStep\u624d\u80fd\u7d81\u5b9a\u8a72feature\n![Calculator](https:\/\/specflow.org\/wp-content\/uploads\/2020\/09\/calculator.png)\nSimple calculator for adding **two** numbers\n\nLink to a feature: [Calculator]($projectname$\/Features\/Calculator.feature)\n***Further read***: **[Learn more about how to generate Living Documentation](https:\/\/docs.specflow.org\/projects\/specflow-livingdoc\/en\/latest\/LivingDocGenerator\/Generating-Documentation.html)**\n\n@mytag # tag\nScenario: Add two numbers # \u60c5\u5883\u7684\u540d\u7a31\uff0c\u4e0d\u80fd\u91cd\u8907\n    Given the first number is 50 # Give \u7d66\u4e88\u53c3\u6578\n    And the second number is 70 # And \u63a5\u7e8c\u4e0a\u4e00\u500b\u7684\u6307\u4ee4\uff0c\u5728\u9019\u662fGiven\n    When the two numbers are added # When \u57f7\u884c\u52d5\u4f5c\n    Then the result should be 120 # Then \u6aa2\u67e5\u7d50\u679c<\/code><\/pre>\n<h4>Step\u5be6\u4f5c<\/h4>\n<p>\u7531\u65bc\u900f\u904e<a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=alexkrechik.cucumberautocomplete\" title=\"Cucumber (Gherkin) Full Support\" rel=\"nofollow noopener\" target=\"_blank\">Cucumber (Gherkin) Full Support<\/a>\u63d2\u4ef6\u6211\u5011\u53ef\u4ee5\u770b\u5230\u90a3\u4e9bfeature\u7684\u8a9e\u53e5\u6c92\u6709\u7d81\u8a02\u5230Step\u4e0a\u9762\uff0c\u6240\u4ee5\u9019\u908a\u53ef\u4ee5\u770b\u4e00\u4e0b\u7bc4\u4f8b\u4e2d\u7684<code>CalculatorStepDefinitions.cs<\/code><\/p>\n<pre><code class=\"language-cs\">[Given(&quot;the first number is (.*)&quot;)]\npublic void GivenTheFirstNumberIs(int number)\n{\n    \/\/TODO: implement arrange (precondition) logic\n    _scenarioContext.Add(&quot;First&quot;, number);\n}\n\n[Given(&quot;the second number is (.*)&quot;)]\npublic void GivenTheSecondNumberIs(int number)\n{\n    \/\/TODO: implement arrange (precondition) logic\n     _scenarioContext.Add(&quot;Second&quot;, number);\n }\n\n[When(&quot;the two numbers are added&quot;)]\npublic void WhenTheTwoNumbersAreAdded()\n{\n    \/\/TODO: implement act (action) logic\n     var first = _scenarioContext.Get&lt;int&gt;(&quot;First&quot;);\n     var second = _scenarioContext.Get&lt;int&gt;(&quot;Second&quot;);\n     var target = new Libs.Calculator();\n    _scenarioContext.Add(&quot;Result&quot;, target.Add(first, second));\n}\n\n[Then(&quot;the result should be (.*)&quot;)]\npublic void ThenTheResultShouldBe(int result)\n{\n    \/\/TODO: implement assert (verification) logic\n     var expect = _scenarioContext.Get&lt;int&gt;(&quot;Result&quot;);\n     Assert.AreEqual(result, expect);\n}<\/code><\/pre>\n<p>\u4e0d\u904e\u5c31\u7b97\u9019\u88dc\u5b8c\u5f8c\u57f7\u884c\u6e2c\u8a66\u4e5f\u662f\u6536\u5230\u932f\u8aa4\uff0c\u56e0\u70ba\u6211\u5011\u539f\u4f86\u7684\u65b9\u6cd5\u672c\u4f86\u5c31\u662f\u932f\u7684\uff0c\u6240\u4ee5\u63a5\u4e0b\u4f86\u518d\u628a\u51fd\u5f0f\u5eab\u7684\u65b9\u6cd5\u4fee\u6b63\u5982\u4e0b\u3002<\/p>\n<pre><code class=\"language-cs\">    public int Add(int first, int second)\n    {\n        return first + second;\n    }<\/code><\/pre>\n<p>\u5982\u6b64\u57f7\u884c\u5b8c\u5f8c\u61c9\u8a72\u6703\u6709\u6e2c\u8a66\u6210\u529f\u7684\u8a0a\u606f\uff0c\u6700\u5f8c\u5728\u8aaa\u660e\u4e00\u4e0b\u5982\u679c\u9700\u8981\u7d81\u5b9a\u67d0\u500bfeature\u7684\u8a71\uff0c\u53ea\u8981\u5728class\u4e0a\u9762\u8a2d\u5b9a\u9019\u500battribute\u5373\u53ef\u3002<\/p>\n<pre><code class=\"language-cs\">[Scope(Feature = &quot;Calculator&quot;)]\n    [Binding]\n    public class CalculatorStepDefinitions<\/code><\/pre>\n<h2>\u5f8c\u8a18<\/h2>\n<p>\u4eca\u5929\u8ddf\u5927\u982d\u9084\u6709\u5c0f\u5149\u4e86\u89e3\u4e86\u8981\u600e\u9ebc\u900f\u904e\u6e2c\u8a66\u6848\u4f8b\u4f86\u589e\u52a0\u7a0b\u5f0f\u7684\u6b63\u78ba\u6027\uff0c\u4e26\u4e14\u5b78\u7fd2\u5230\u5982\u4f55\u900f\u904evscode\u4f86\u64b0\u5bebspecflow\u7684features\u3002\u5e0c\u671b\u5c0d\u5927\u5bb6\u6e1b\u5c11bug\u6709\u6240\u5e6b\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u64b0\u5beb\u6e2c\u8a66 \u76f8\u4fe1\u5f88\u591a\u4eba\u6703\u60f3\u8981\u589e\u52a0\u7cfb\u7d71\u7684\u7a69\u5b9a\u5ea6\uff0c\u4f46\u662f\u9019\u8a72\u5982\u4f55\u505a\u5247\u662f\u500b\u554f\u984c\uff0c\u76f8\u4fe1\u5f88\u591a\u4eba\u770b\u904e91 TDD\u7684\u6587\u7ae0\uff0c\u4e5f\u76f8\u4fe1 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.develop-note.com\/blog\/2021\/10\/11\/mstest-specflow\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008D-04-\u958b\u59cb\u6e2c\u8a66 ? mstest ? specflow\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[90,92,146],"class_list":["post-2508","post","type-post","status-publish","format-standard","hentry","category-develop","tag-2021ironman","tag-dotnetcore","tag-specflow"],"_links":{"self":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2508","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/comments?post=2508"}],"version-history":[{"count":32,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2508\/revisions"}],"predecessor-version":[{"id":2924,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2508\/revisions\/2924"}],"wp:attachment":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/media?parent=2508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/categories?post=2508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/tags?post=2508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}