{"id":333423,"date":"2022-05-20T15:00:40","date_gmt":"2022-05-20T15:00:40","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=333423"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=333423","title":{"rendered":"<span>\u0412\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 Unit \u0442\u0435\u0441\u0442\u044b \u0432 Dart\/Flutter<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u044b. \u0418 \u043f\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u044f \u043f\u0438\u0441\u0430\u0442\u0435\u043b\u0435\u043c \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f, \u0430 \u043d\u0435 \u0441\u043a\u0443\u0447\u043d\u043e\u0433\u043e, \u0442\u044f\u0436\u0435\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<p>\u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 TDD \u0438 BDD. \u042f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0443, \u0447\u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0438\u043b\u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0441\u043b\u044b\u0448\u0430\u043b\u0438, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u0442\u0435\u0445\u043d\u0438\u043a\u0438. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"https:\/\/www.youtube.com\/watch?v=FWra0ORVios\" rel=\"noopener noreferrer nofollow\">\u0432\u0438\u0434\u0435\u043e-\u0443\u0440\u043e\u043a \u043f\u043e TDD \u0442\u0443\u0442<\/a> \u0438 \u043f\u0440\u043e <a href=\"https:\/\/youtu.be\/1j9UoOX7Iqs\" rel=\"noopener noreferrer nofollow\">BDD (\u0432\u0438\u0434\u0435\u043e \u0432\u0435\u0440\u0441\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0442\u0443\u0442)<\/a><\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6283b326de22274fb4bad968\" data-style=\"\" id=\"6283b326de22274fb4bad968\" width=\"\"><\/div>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/62877ef441d6a34fa4f7f1a8\" data-style=\"\" id=\"62877ef441d6a34fa4f7f1a8\" width=\"\"><\/div>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 BDD?<\/h2>\n<p><strong>BDD<\/strong> \u0438\u043b\u0438 <strong>Behaviour Driven Development<\/strong> &#8212; \u044d\u0442\u043e \u043f\u043e\u0434\u0445\u043e\u0434 \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0438\u043a\u0442\u0443\u0435\u0442\u0441\u044f <strong>\u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f\u043c\u0438<\/strong> \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p><strong>BDD<\/strong> &#8212; \u044d\u0442\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043d\u0430\u0434 <strong>TDD<\/strong>.<\/p>\n<p><strong>TDD<\/strong> (<strong>Test-driven development<\/strong>) \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 <em>&#171;\u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432 \u043f\u0435\u0440\u0435\u0434 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439&#187;<\/em>. \u0410 <strong>BDD<\/strong> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442, \u0447\u0442\u043e \u0442\u0435\u0441\u0442\u044b (\u0438\u043b\u0438 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438) \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c <em>&#171;\u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b&#187;<\/em>, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u0445 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u044e\u043d\u0438\u0442\u0430 (\u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438).<\/p>\n<h2>\u0417\u0430\u0447\u0435\u043c BDD?<\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3a8\/d5a\/707\/3a8d5a7076de916421b1f9ff0586ecee.png\" width=\"2457\" height=\"849\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3a8\/d5a\/707\/3a8d5a7076de916421b1f9ff0586ecee.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0435\u0441\u0442\u044c \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0434\u0432\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b. \u041f\u0435\u0440\u0432\u0430\u044f &#8212; \u0431\u0438\u0437\u043d\u0435\u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 (Business Owners, \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438, \u0438 \u0434\u0440\u0443\u0433\u0438\u0435, \u043a\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u0430\u043c\u0438), \u0438 \u0432\u0442\u043e\u0440\u0430\u044f &#8212; \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u0432). \u0418 \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u0431\u0440\u044b\u0432 \u0432 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438 &#8212; &#171;\u0411\u0438\u0437\u043d\u0435\u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432&#187;, \u0430 &#171;\u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0447\u0435\u0442\u043a\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u0438\u0437\u043d\u0435\u0441&#187; \u0438\u043c \u043d\u0443\u0436\u0435\u043d \u00ab\u043e\u0431\u0449\u0438\u0439\u00bb  \u044f\u0437\u044b\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043d\u044f\u0442\u0435\u043d \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u0438 \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <strong>BDD<\/strong> \u0438 \u0435\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438.<\/p>\n<h2>BDD \u0441\u0442\u0438\u043b\u044c<\/h2>\n<p>\u0427\u0442\u043e \u044f \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u044e \u043f\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 <strong>\u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c\u0438<\/strong> \u0442\u0435\u0441\u0442\u0430\u043c\u0438?<\/p>\n<p>\u042d\u0442\u043e <strong>BDD \u0441\u0442\u0438\u043b\u044c<\/strong> \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 (\u0438\u043b\u0438 \u0442\u0435\u0441\u0442\u043e\u0432).<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0434\u043b\u044f <code>PNL-\u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430<\/code>:<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6283a7e715db00b4622648b3\" data-style=\"\" id=\"6283a7e715db00b4622648b3\" width=\"\"><\/div>\n<p>BDD \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 (\u0442\u0435\u0441\u0442\u044b) \u043f\u0438\u0448\u0443\u0442\u0441\u044f \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u0443 <strong>GIVEN-WHEN-THEN<\/strong>:<\/p>\n<p>&#8212; <strong>GIVEN<\/strong> &#8212; \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u043b\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0442.\u0435. \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e 1000 \u043c\u043e\u043d\u0435\u0442 \u0438 \u0437\u0430\u0442\u0440\u0430\u0442\u0438\u043b\u0438 $1000 \u043d\u0430 \u0438\u0445 \u043f\u043e\u043a\u0443\u043f\u043a\u0443, \u0438\u043b\u0438 \u0446\u0435\u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u043c\u043e\u043d\u0435\u0442\u043a\u0438 \u0431\u044b\u043b\u0430 $1;<\/p>\n<p>&#8212; <strong>WHEN<\/strong>  &#8212; \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c, \u0442.\u0435. \u0446\u0435\u043d\u0430 \u043c\u043e\u043d\u0435\u0442\u043a\u0438 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0438 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440 \u043d\u0430\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f;<\/p>\n<p>&#8212; <strong>THEN<\/strong> &#8212; \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438\u043b\u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0442.\u0435. \u043d\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0444\u0438\u0442, \u0443\u0431\u044b\u0442\u043e\u043a \u0438\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c.<\/p>\n<h2>\u0422\u0440\u0438 \u0447\u0430\u0441\u0442\u0438 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e  \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0440\u0438 \u0447\u0430\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u043c\u0438. \u042d\u0442\u043e:<\/p>\n<p>&#8212; \u043a\u043e\u0434 \u0441\u0430\u043c\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432;<\/p>\n<p>&#8212; \u043e\u0442\u0447\u0435\u0442 \u043e\u0431 \u0443\u0441\u043f\u0435\u0445\u0435 \u0438\u043b\u0438 \u043e \u043f\u0440\u043e\u0432\u0430\u043b\u0435;<\/p>\n<p>&#8212; \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0432\u0430\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430.<\/p>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u044d\u0442\u0438\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u0430:<\/p>\n<p>&#8212; \u0415\u0441\u043b\u0438 <strong>\u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430<\/strong> \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d, \u0442\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u0434\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u043d\u0435\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u0441\u0430\u043c\u043e\u043c\u0443, \u0438\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043f\u043e\u0439\u043c\u0435\u0442 \u043e \u0447\u0435\u043c \u0442\u0435\u0441\u0442, \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0441\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442 \u0441\u0430\u043c.<\/p>\n<p>&#8212; <strong>\u041e\u0442\u0447\u0435\u0442<\/strong> &#8212; \u043c\u043e\u0436\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f &#171;\u0436\u0438\u0432\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439&#187;, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0438 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0447\u043b\u0435\u043d \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0434\u0430\u0436\u0435 \u043d\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442.<\/p>\n<p>&#8212; \u0415\u0441\u043b\u0438 <strong>\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435<\/strong> \u044f\u0441\u043d\u043e \u0440\u0430\u0437\u044a\u044f\u0441\u043d\u044f\u0435\u0442 \u043f\u0440\u0438\u0447\u0438\u043d\u0443 \u043e\u0448\u0438\u0431\u043a\u0438, \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435.<\/p>\n<p>\u041a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u044d\u0442\u0438\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c.<\/p>\n<h2>PNL \u041a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440<\/h2>\n<p>\u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <code>PNL \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430<\/code> \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u0445.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u0442\u0440\u0438 \u0441\u043b\u0443\u0447\u0430\u044f:<\/p>\n<p>&#8212; \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043d\u0430 \u043c\u043e\u043d\u0435\u0442\u043a\u0438 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 &#8212; \u043f\u0440\u043e\u0444\u0438\u0442 (profit);<\/p>\n<p>&#8212; \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043d\u0430 \u043c\u043e\u043d\u0435\u0442\u043a\u0438 \u0441\u043d\u0438\u0437\u0438\u043b\u0430\u0441\u044c &#8212; \u0443\u0431\u044b\u0442\u043e\u043a (loss);<\/p>\n<p>&#8212; \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043d\u0430 \u043c\u043e\u043d\u0435\u0442\u043a\u0438 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c.<\/p>\n<p>BDD \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f \u043f\u0440\u043e\u0444\u0438\u0442\u0430:<\/p>\n<pre><code>Given 1000 coins with a total investment of $1000 When coin price raise up to $2 Then PNL % should be 100%   And PNL value should be $1000   And holding value should be $2000<\/code><\/pre>\n<p>\u042e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442 \u043c\u043e\u0433 \u0431\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"dart\">group('Given 1000 coins with a total investment of \\$1000 ', () {   const coinAmount = 1000.0;   const totalInvestment = 1000.0;    group('\\nWhen coin price raise up to \\$2', () {     late PnlCalculatorResult pnl;     setUp(() {       pnl = PnlCalculator.calculate(         coinAmount: coinAmount,         totalInvestments: totalInvestment,         currentPrice: 2,       );     });     test('\\nThen PNL % should be 100%', () {       expect(pnl.percent, 100);     });      test('\\n    And PNL value should be \\$1000', () {       expect(pnl.value, 1000);     });      test('\\n    And holding value should be \\$2000', () {       expect(pnl.holdingValue, 2000);     });   }); });<\/code><\/pre>\n<p>\u0418 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043c\u044b \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438, \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u0442\u0430\u043a\u043e\u0433\u043e:<\/p>\n<pre><code>\u2713 Given 1000 coins with a total investment of $1000   When coin price raise up to $2  Then PNL % should be 100% \u2713 Given 1000 coins with a total investment of $1000   When coin price raise up to $2      And PNL value should be $1000 \u2713 Given 1000 coins with a total investment of $1000   When coin price raise up to $2      And holding value should be $2000<\/code><\/pre>\n<p>\u041a\u0430\u043a\u0438\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b c \u044d\u0442\u0438\u043c \u0442\u0435\u0441\u0442\u043e\u043c \u0438 \u043e\u0442\u0447\u0435\u0442\u043e\u043c?<\/p>\n<p>&#8212; \u041a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430 \u0442\u044f\u0436\u0435\u043b\u043e \u0447\u0438\u0442\u0430\u0442\u044c. \u0422\u0443\u0442 \u0435\u0441\u0442\u044c \u0438 <code>group<\/code>, <code>setUp<\/code> \u0438 <code>test<\/code> \u0442\u0435\u0440\u043c\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0438 \u043c\u0435\u0448\u0430\u044e\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043e \u0447\u0435\u043c \u0442\u0435\u0441\u0442. \u0410 BDD \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u043b\u043e\u0432 \u0438 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043e\u043a, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u0439 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0434\u0430\u0436\u0435 \u0434\u0430\u043b\u0435\u043a\u0438\u0439 \u043e\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0435\u0441\u0442 \u0438 \u043f\u043e\u043d\u044f\u0442\u044c \u043e \u0447\u0435\u043c \u043e\u043d.<\/p>\n<p>&#8212; \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043e\u0442\u0447\u0435\u0442, \u0442\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u043c \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u043e\u0432 <code>GIVEN<\/code> \u0438 <code>WHEN<\/code>, \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0430 <code>THEN<\/code> \u0438 <code>AND<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0447\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0440\u043e\u0432\u043d\u043e \u0442\u0430\u043a, \u043a\u0430\u043a \u0441\u0430\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439. \u0418 <code>\\n<\/code> \u0441 \u0442\u0430\u0431\u0443\u043b\u044f\u0446\u0438\u0435\u0439 \u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u0430 \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u0440\u0442\u044f\u0442 \u043a\u043e\u0434 \u0441\u0430\u043c\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430.<\/p>\n<p>\u0418 \u0442\u0443\u0442 \u043a \u043d\u0430\u043c \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 Dart-\u043f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/pub.dev\/packages\/given_when_then_unit_test\" rel=\"noopener noreferrer nofollow\">given_when_then_unit_test<\/a>. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e, \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"dart\">given('1000 coins with a total investment of \\$1000', () {   const coinAmount = 1000.0;   const totalInvestment = 1000.0;    when('coin price raise up to \\$2', () {     late PnlCalculatorResult pnl;     before(() {       pnl = PnlCalculator.calculate(         coinAmount: coinAmount,         totalInvestments: totalInvestment,         currentPrice: 2,       );     });      then('PNL % should be 100%', () => expect(pnl.percent, 100), and: {       'PNL value should be \\$1000': () => expect(pnl.value, 1000),       'holding value should be \\$2000': () => expect(pnl.holdingValue, 2000),     });   }); });<\/code><\/pre>\n<p>\u0418 \u043e\u0442\u0447\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f \u0438 \u0441\u0430\u043c \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430 <s>\u0442\u043e\u0447\u043d\u043e<\/s> \u043f\u043e\u0447\u0442\u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f.<\/p>\n<pre><code>Given 1000 coins with a total investment of $1000  When coin price raise up to $2  Then PNL % should be 100%   And PNL value should be $1000   And holding value should be $2000<\/code><\/pre>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/62839e6415db00b4622648b2\" data-style=\"\" id=\"62839e6415db00b4622648b2\" width=\"\"><\/div>\n<h2>Shouldly<\/h2>\n<blockquote>\n<p>\u0438 \u0441\u0430\u043c \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430 <s>\u0442\u043e\u0447\u043d\u043e<\/s> \u043f\u043e\u0447\u0442\u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f.<\/p>\n<\/blockquote>\n<p>&#8230;\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0432\u043e\u0442 \u044d\u0442\u0438\u0445 \u0441\u0442\u0440\u043e\u043a \u0441 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"dart\">then('PNL % should be 100%', () => expect(pnl.percent, 100), and: {   'PNL value should be \\$1000': () => expect(pnl.value, 1000),   'holding value should be \\$2000': () => expect(pnl.holdingValue, 2000), });<\/code><\/pre>\n<p>\u041d\u043e \u044d\u0442\u043e \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0442\u043e\u0440\u043e\u0433\u043e Dart-\u043f\u0430\u043a\u0435\u0442\u0430 <a href=\"https:\/\/pub.dev\/packages\/shouldly\" rel=\"noopener noreferrer nofollow\">shouldly<\/a>. \u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0449\u0435 \u0438 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0418 \u044d\u0442\u0438 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u043a\u0430\u043a:<\/p>\n<pre><code>expect(pnl.percent, 100)       => pnl.percent.should.be(100) expect(pnl.value, 1000)        => pnl.value.should.be(1000) expect(pnl.holdingValue, 2000) => pnl.holdingValue.should.be(2000)<\/code><\/pre>\n<p>\u0418 \u0442\u0430\u043a\u0438\u043c \u0432\u043e\u0442 \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f:<\/p>\n<pre><code class=\"dart\">then(   'PNL % should be 100%', () => pnl.percent.should.be(100),   and: {     'PNL value should be \\$1000': () => pnl.value.should.be(1000),     'holding value should be \\$2000': () => pnl.holdingValue.should.be(2000),   }, );<\/code><\/pre>\n<h2>\u0411\u043e\u043b\u044c\u0448\u0435 \u0444\u0438\u0448\u0435\u043a<\/h2>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0447\u0438\u043d, \u043f\u043e\u0447\u0435\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>shouldly<\/code>.  <\/p>\n<p><strong>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u043e\u0432\u0430\u043b\u0430 \u0442\u0435\u0441\u0442\u0430<\/strong><\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0434\u0432\u0430 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u043d\u0435 \u0440\u0430\u0432\u043d\u044b, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043f\u0440\u0438\u0447\u0438\u043d\u0443 \u043e \u043f\u0440\u043e\u0432\u0430\u043b\u0435 \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code>Expected: &lt;10>   Actual: &lt;100><\/code><\/pre>\n<p>\u041a\u0442\u043e \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 100 \u0438 10? \u041a\u0430\u043a\u0438\u0435 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0447\u0442\u043e \u0442\u0430\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442\u0441\u044f? \u0423 \u043d\u0430\u0441 \u043d\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u0422\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u043b\u043e\u0433\u0430\u0445 \u0438 \u043d\u0430\u0439\u0442\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0430, \u0442\u043e \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c. \u0410 \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u0442\u0435\u0441\u0442\u0435 \u0434\u0432\u0430 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f, \u0447\u0435\u0433\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0438 \u043e \u0447\u0435\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u0432 <a href=\"https:\/\/www.youtube.com\/watch?v=FWra0ORVios&amp;t=1632s\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u043c \u0432\u0438\u0434\u0435\u043e<\/a>.<\/p>\n<pre><code class=\"dart\">test('many expectations in single test', () {   expect(hero.health, 100);   expect(hero.strength, 100); });<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0443\u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043d\u0435\u0432\u0435\u0440\u043d\u043e? \u041d\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u044f\u0442\u044c \u0442\u0430\u043a\u0438 \u0432 \u043b\u043e\u0433\u0430\u0445 \u043f\u043e\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0438 \u043d\u0430\u0439\u0442\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0443. \u0418\u043b\u0438 \u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>reason<\/code> \u0432 <code>expect<\/code>:<\/p>\n<pre><code>expect(hero.health, 100, reason: 'Health in the beginning should be 100'); expect(hero.strength, 100);<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0432\u0430\u043b\u0430 \u0442\u0435\u0441\u0442\u0430 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e. \u041d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u043d\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e.<\/p>\n<pre><code>Expected: &lt;100>   Actual: &lt;10> Health in the beginning should be 100<\/code><\/pre>\n<p>\u0421 <code>shouldly<\/code> \u044d\u0442\u043e \u0436\u0435 \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>hero.health.should.be(100);<\/code><\/pre>\n<p>\u0418 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u043f\u0440\u043e\u0432\u0430\u043b\u0435 \u0442\u0435\u0441\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code>Expected `int`     should be 100     but was 10<\/code><\/pre>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 <code>.as('some alias').<\/code>:<\/p>\n<pre><code>hero.health.should.as('hero\\'s health').be(100);<\/code><\/pre>\n<p>\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0435 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043f\u0440\u043e\u0432\u0430\u043b\u0430 \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code>Expected `hero's health`     should be 100     but was 10<\/code><\/pre>\n<p>\u0416\u0430\u043b\u044c, \u0447\u0442\u043e \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f \u0432 Dart \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435 \u0442\u0430\u043a \u043a\u0430\u043a \u0432 .NET. \u0412 .NET \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043e\u0439 \u0438 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435 \u0438 \u043d\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>.as('some alias').<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e <a href=\"https:\/\/docs.shouldly.io\/documentation\/equality\/shouldbe\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>. \u041d\u043e \u043a\u0442\u043e \u0437\u043d\u0430\u0435\u0442, \u043c\u043e\u0436\u0435\u0442 \u0442\u0430\u043a\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u0435\u0449\u0451 \u0432 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f\u0445 Dart&#8217;\u0430.<\/p>\n<p><strong>\u041f\u0443\u0442\u0430\u043d\u0438\u0446\u0430 actual \u0441 expected<\/strong><\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>expect<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 <code>matcher<\/code> (\u0438\u043b\u0438 <code>expected<\/code>), \u0430 \u0434\u0440\u0443\u0433\u043e\u0439 <code>actual<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c, \u0441\u043a\u0430\u0436\u0438\u0442\u0435, \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>expect<\/code>, \u0430 \u043a\u0430\u043a\u043e\u0439 \u0432\u0442\u043e\u0440\u044b\u043c?<\/p>\n<pre><code class=\"dart\">final actual = 0; final expected = 0;  expect(actual, expected); expect(expected, actual);<\/code><\/pre>\n<p>\u041e\u0431\u0430 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b\u0445 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0439\u0434\u0443\u0442.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u0430\u0442\u0447\u0435\u0440 <code>isZero<\/code>.<\/p>\n<pre><code class=\"dart\">final actual = 0;  expect(actual, isZero); expect(isZero, actual);<\/code><\/pre>\n<p>\u0414\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0442\u0435\u0441\u0442\u0430 \u0432\u0440\u043e\u0434\u0435 \u0432\u0441\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0445\u043e\u0440\u043e\u0448\u043e &#8212; \u043e\u0448\u0438\u0431\u043e\u043a \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043d\u0435\u0442.<\/p>\n<p>\u041d\u041e! \u0412\u0442\u043e\u0440\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u0442, \u0438 \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0447\u0435\u043d\u044c \u0441\u0442\u0440\u0430\u043d\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<pre><code>Expected: &lt;0>   Actual: a value equal to &lt;0><\/code><\/pre>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6283a0adea15664f98adaa38\" data-style=\"\" id=\"6283a0adea15664f98adaa38\" width=\"\"><\/div>\n<p><strong>\u041a\u0443\u0447\u043a\u0430 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0439<\/strong><\/p>\n<p>\u0412 <code>shouldly<\/code> \u043d\u0435 \u0441\u0432\u0430\u043b\u0435\u043d\u043d\u043e \u0432\u0441\u0451 \u0432 \u043e\u0434\u043d\u0443 \u043a\u0443\u0447\u0443, \u0432\u0441\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043c\u0430\u0442\u0447\u0435\u0440\u044b.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0442\u0438\u043f \u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0441 <code>expect<\/code>:<\/p>\n<pre><code class=\"dart\">expect(0, isEmpty);<\/code><\/pre>\n<p>\u0412 <code>shouldy<\/code> \u0432\u0441\u0451 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0438\u043f\u0430 \u0442\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cfc\/bd8\/a76\/cfcbd8a76e6dbc5194a362664f7463cc.png\" width=\"626\" height=\"510\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cfc\/bd8\/a76\/cfcbd8a76e6dbc5194a362664f7463cc.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"float bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d22\/2e8\/1dd\/d222e81dd59003e0d5f68cce557f84b5.png\" width=\"626\" height=\"510\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d22\/2e8\/1dd\/d222e81dd59003e0d5f68cce557f84b5.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5d3\/3db\/5b4\/5d33db5b4ab1f522862ebadf7d5cd538.png\" width=\"688\" height=\"348\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5d3\/3db\/5b4\/5d33db5b4ab1f522862ebadf7d5cd538.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u2139\ufe0f \u0414\u0440\u0443\u0433\u0438\u0435 \u0444\u0438\u0447\u0438 \u043a\u0430\u043a<\/p>\n<p>&#8212; <a href=\"https:\/\/pub.dev\/packages\/shouldly#custom-matchers\" rel=\"noopener noreferrer nofollow\">Custom matchers<\/a>,<\/p>\n<p>&#8212; <a href=\"https:\/\/pub.dev\/packages\/shouldly#conjunctions\" rel=\"noopener noreferrer nofollow\">Conjunctions<\/a>,<\/p>\n<p>&#8212; <a href=\"https:\/\/pub.dev\/packages\/shouldly#satisfyallconditions\" rel=\"noopener noreferrer nofollow\">SatisfyAllConditions<\/a> <\/p>\n<p>&#8212; \u0438 \u0434\u0440. \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435  <a href=\"https:\/\/pub.dev\/packages\/shouldly\" rel=\"noopener noreferrer nofollow\">\u0441\u0430\u043c\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0430 pub.dev<\/a><\/p>\n<h2>\u0422\u0435\u0441\u0442-\u043a\u0435\u0439\u0441\u044b<\/h2>\n<p>\u0412 \u0438\u0434\u0435\u0430\u043b\u0435, \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u0443\u0447\u0430\u0435\u0432 (<strong>\u0442\u0435\u0441\u0442-\u043a\u0435\u0439\u0441\u043e\u0432<\/strong>). \u0418 \u043f\u0440\u0438 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430. \u041d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 <code>testCases<\/code> \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 <em>\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/em> \u0442\u0435\u0441\u0442.<\/p>\n<p>\u0423 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043f\u0435\u0440\u0432\u044b\u0439 &#8212; \u044d\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <code>TestCase<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 &#8212; \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0435\u0441\u0442-\u043a\u0435\u0439\u0441.<\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441 <code>PnL \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u043c<\/code> \u043c\u044b \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0449\u0435 \u0434\u0432\u0430 \u0442\u0435\u0441\u0442-\u043a\u0435\u0439\u0441\u0430: \u043e\u0434\u0438\u043d \u043d\u0430 \u0443\u0431\u044b\u0442\u043e\u043a (loss), \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0446\u0435\u043d\u0435 \u043c\u043e\u043d\u0435\u0442\u043a\u0438.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u0442\u0435\u0441\u0442 \u0441 \u043a\u0435\u0439\u0441\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c:<\/p>\n<pre><code class=\"dart\">given('1000 coins and with a total investment of \\$1000', () {   final coinAmount = 1000.0;   final totalInvestment = 1000.0;    testCases4&lt;double, double, double, double>([     TestCase4(2, 100, 1000, 2000),     TestCase4(.1, -90, -900, 100),     TestCase4(1, 0, 0, 1000),     \/\/ ...more Test Cases   ], (testCase) {     when('the coin price became \\$${testCase.arg1}', () {       late PnlCalculatorResult pnl;       before(() {         pnl = PnlCalculator.calculate(           coinAmount: coinAmount,           totalInvestments: totalInvestment,           currentPrice: testCase.arg1,         );       });        then(         'PNL % should be ${testCase.arg2}%',         () => pnl.percent.should.be(testCase.arg2),         and: {           'PNL value should be \\$${testCase.arg3}': () =>               pnl.value.should.be(testCase.arg3),           'holding value should be \\$${testCase.arg4}': () =>               pnl.holdingValue.should.be(testCase.arg4),         },       );     });   }); });<\/code><\/pre>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6283a1b2b73444b4a1d3fdcc\" data-style=\"\" id=\"6283a1b2b73444b4a1d3fdcc\" width=\"\"><\/div>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0432\u0443\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 <a href=\"https:\/\/pub.dev\/packages\/given_when_then_unit_test\" rel=\"noopener noreferrer nofollow\">given_when_then_unit_test<\/a> \u0438 <a href=\"https:\/\/pub.dev\/packages\/shouldly\" rel=\"noopener noreferrer nofollow\">shouldly<\/a> \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c:<\/p>\n<p>1) \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u0442\u0435\u0441\u0442\u043e\u0432,<\/p>\n<p>2) \u043e\u0442\u0447\u0435\u0442\u043e\u0432 \u043f\u043e \u0442\u0435\u0441\u0442\u0430\u043c,<\/p>\n<p>3) \u0438, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0432\u0430\u043b\u0430 \u0442\u0435\u0441\u0442\u0430, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u043f\u0440\u0438\u0447\u0438\u043d\u0443 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/368\/08a\/344\/36808a3449f6a75cea18851bfe99396d.png\" width=\"1320\" height=\"480\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/368\/08a\/344\/36808a3449f6a75cea18851bfe99396d.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c,<\/p>\n<p>&#8212; \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u0443\u044e \u0442\u0435\u0445\u043d\u0438\u043a\u0443 BDD \u0441\u0442\u0438\u043b\u044f \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438. \u041d\u043e \u0442\u0430\u043c \u0433\u0434\u0435 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c <em>\u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/em> \u044e\u043d\u0438\u0442\u0430, \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u0431\u0440\u0430\u0442\u044c \u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c &#171;\u0436\u0438\u0432\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e&#187;;<\/p>\n<p>&#8212; \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u044d\u0442\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u043e\u043d\u0438 \u0434\u0430\u044e\u0442 \u0448\u0438\u043a\u0430\u0440\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<p>\u0423\u0434\u0430\u0447\u0438 \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f! ?<\/p>\n<h2>Contribution<\/h2>\n<p>\u041a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0434\u0430\u043d\u043d\u0430\u044f \u0442\u0435\u043c\u0430 \u0438 \u0443 \u043a\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0438\u0434\u0435\u0438, \u043a\u0430\u043a \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u0430\u043a\u0435\u0442\u044b, \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u0432 \u0441\u043e\u0430\u0432\u0442\u043e\u0440\u044b.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/666196\/\"> https:\/\/habr.com\/ru\/post\/666196\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u044b. \u0418 \u043f\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u044f \u043f\u0438\u0441\u0430\u0442\u0435\u043b\u0435\u043c \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f, \u0430 \u043d\u0435 \u0441\u043a\u0443\u0447\u043d\u043e\u0433\u043e, \u0442\u044f\u0436\u0435\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<p>\u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 TDD \u0438 BDD. \u042f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0443, \u0447\u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0438\u043b\u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0441\u043b\u044b\u0448\u0430\u043b\u0438, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u0442\u0435\u0445\u043d\u0438\u043a\u0438. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"https:\/\/www.youtube.com\/watch?v=FWra0ORVios\" rel=\"noopener noreferrer nofollow\">\u0432\u0438\u0434\u0435\u043e-\u0443\u0440\u043e\u043a \u043f\u043e TDD \u0442\u0443\u0442<\/a> \u0438 \u043f\u0440\u043e <a href=\"https:\/\/youtu.be\/1j9UoOX7Iqs\" rel=\"noopener noreferrer nofollow\">BDD (\u0432\u0438\u0434\u0435\u043e \u0432\u0435\u0440\u0441\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0442\u0443\u0442)<\/a><\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6283b326de22274fb4bad968\" data-style=\"\" id=\"6283b326de22274fb4bad968\" width=\"\"><\/div>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/62877ef441d6a34fa4f7f1a8\" data-style=\"\" id=\"62877ef441d6a34fa4f7f1a8\" width=\"\"><\/div>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 BDD?<\/h2>\n<p><strong>BDD<\/strong> \u0438\u043b\u0438 <strong>Behaviour Driven Development<\/strong> &#8212; \u044d\u0442\u043e \u043f\u043e\u0434\u0445\u043e\u0434 \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0438\u043a\u0442\u0443\u0435\u0442\u0441\u044f <strong>\u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f\u043c\u0438<\/strong> \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p><strong>BDD<\/strong> &#8212; \u044d\u0442\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u043d\u0430\u0434 <strong>TDD<\/strong>.<\/p>\n<p><strong>TDD<\/strong> (<strong>Test-driven development<\/strong>) \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 <em>&#171;\u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432 \u043f\u0435\u0440\u0435\u0434 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439&#187;<\/em>. \u0410 <strong>BDD<\/strong> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442, \u0447\u0442\u043e \u0442\u0435\u0441\u0442\u044b (\u0438\u043b\u0438 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438) \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c <em>&#171;\u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b&#187;<\/em>, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u0445 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u044e\u043d\u0438\u0442\u0430 (\u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438).<\/p>\n<h2>\u0417\u0430\u0447\u0435\u043c BDD?<\/h2>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0435\u0441\u0442\u044c \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0434\u0432\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b. \u041f\u0435\u0440\u0432\u0430\u044f &#8212; \u0431\u0438\u0437\u043d\u0435\u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 (Business Owners, \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438, \u0438 \u0434\u0440\u0443\u0433\u0438\u0435, \u043a\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u0430\u043c\u0438), \u0438 \u0432\u0442\u043e\u0440\u0430\u044f &#8212; \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 (\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u0432). \u0418 \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u0431\u0440\u044b\u0432 \u0432 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438 &#8212; &#171;\u0411\u0438\u0437\u043d\u0435\u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432&#187;, \u0430 &#171;\u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0447\u0435\u0442\u043a\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u0438\u0437\u043d\u0435\u0441&#187; \u0438\u043c \u043d\u0443\u0436\u0435\u043d \u00ab\u043e\u0431\u0449\u0438\u0439\u00bb  \u044f\u0437\u044b\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043d\u044f\u0442\u0435\u043d \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u0438 \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <strong>BDD<\/strong> \u0438 \u0435\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438.<\/p>\n<h2>BDD \u0441\u0442\u0438\u043b\u044c<\/h2>\n<p>\u0427\u0442\u043e \u044f \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u044e \u043f\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 <strong>\u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c\u0438<\/strong> \u0442\u0435\u0441\u0442\u0430\u043c\u0438?<\/p>\n<p>\u042d\u0442\u043e <strong>BDD \u0441\u0442\u0438\u043b\u044c<\/strong> \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 (\u0438\u043b\u0438 \u0442\u0435\u0441\u0442\u043e\u0432).<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0434\u043b\u044f <code>PNL-\u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430<\/code>:<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6283a7e715db00b4622648b3\" data-style=\"\" id=\"6283a7e715db00b4622648b3\" width=\"\"><\/div>\n<p>BDD \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 (\u0442\u0435\u0441\u0442\u044b) \u043f\u0438\u0448\u0443\u0442\u0441\u044f \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u0443 <strong>GIVEN-WHEN-THEN<\/strong>:<\/p>\n<p>&#8212; <strong>GIVEN<\/strong> &#8212; \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u043b\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0442.\u0435. \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e 1000 \u043c\u043e\u043d\u0435\u0442 \u0438 \u0437\u0430\u0442\u0440\u0430\u0442\u0438\u043b\u0438 $1000 \u043d\u0430 \u0438\u0445 \u043f\u043e\u043a\u0443\u043f\u043a\u0443, \u0438\u043b\u0438 \u0446\u0435\u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u043c\u043e\u043d\u0435\u0442\u043a\u0438 \u0431\u044b\u043b\u0430 $1;<\/p>\n<p>&#8212; <strong>WHEN<\/strong>  &#8212; \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c, \u0442.\u0435. \u0446\u0435\u043d\u0430 \u043c\u043e\u043d\u0435\u0442\u043a\u0438 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0438 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440 \u043d\u0430\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f;<\/p>\n<p>&#8212; <strong>THEN<\/strong> &#8212; \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438\u043b\u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0442.\u0435. \u043d\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0444\u0438\u0442, \u0443\u0431\u044b\u0442\u043e\u043a \u0438\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c.<\/p>\n<h2>\u0422\u0440\u0438 \u0447\u0430\u0441\u0442\u0438 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e  \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0440\u0438 \u0447\u0430\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u043c\u0438. \u042d\u0442\u043e:<\/p>\n<p>&#8212; \u043a\u043e\u0434 \u0441\u0430\u043c\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432;<\/p>\n<p>&#8212; \u043e\u0442\u0447\u0435\u0442 \u043e\u0431 \u0443\u0441\u043f\u0435\u0445\u0435 \u0438\u043b\u0438 \u043e \u043f\u0440\u043e\u0432\u0430\u043b\u0435;<\/p>\n<p>&#8212; \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0432\u0430\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430.<\/p>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u044d\u0442\u0438\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u0430:<\/p>\n<p>&#8212; \u0415\u0441\u043b\u0438 <strong>\u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430<\/strong> \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d, \u0442\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u0434\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u043d\u0435\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u0441\u0430\u043c\u043e\u043c\u0443, \u0438\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043f\u043e\u0439\u043c\u0435\u0442 \u043e \u0447\u0435\u043c \u0442\u0435\u0441\u0442, \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0441\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442 \u0441\u0430\u043c.<\/p>\n<p>&#8212; <strong>\u041e\u0442\u0447\u0435\u0442<\/strong> &#8212; \u043c\u043e\u0436\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f &#171;\u0436\u0438\u0432\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439&#187;, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0438 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0447\u043b\u0435\u043d \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0434\u0430\u0436\u0435 \u043d\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442.<\/p>\n<p>&#8212; \u0415\u0441\u043b\u0438 <strong>\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435<\/strong> \u044f\u0441\u043d\u043e \u0440\u0430\u0437\u044a\u044f\u0441\u043d\u044f\u0435\u0442 \u043f\u0440\u0438\u0447\u0438\u043d\u0443 \u043e\u0448\u0438\u0431\u043a\u0438, \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435.<\/p>\n<p>\u041a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u044d\u0442\u0438\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u0441\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c.<\/p>\n<h2>PNL \u041a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440<\/h2>\n<p>\u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <code>PNL \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430<\/code> \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u0445.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u0442\u0440\u0438 \u0441\u043b\u0443\u0447\u0430\u044f:<\/p>\n<p>&#8212; \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043d\u0430 \u043c\u043e\u043d\u0435\u0442\u043a\u0438 \u0432\u044b\u0440\u043e\u0441\u043b\u0430 &#8212; \u043f\u0440\u043e\u0444\u0438\u0442 (profit);<\/p>\n<p>&#8212; \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043d\u0430 \u043c\u043e\u043d\u0435\u0442\u043a\u0438 \u0441\u043d\u0438\u0437\u0438\u043b\u0430\u0441\u044c &#8212; \u0443\u0431\u044b\u0442\u043e\u043a (loss);<\/p>\n<p>&#8212; \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043d\u0430 \u043c\u043e\u043d\u0435\u0442\u043a\u0438 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c.<\/p>\n<p>BDD \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f \u043f\u0440\u043e\u0444\u0438\u0442\u0430:<\/p>\n<pre><code>Given 1000 coins with a total investment of $1000 When coin price raise up to $2 Then PNL % should be 100%   And PNL value should be $1000   And holding value should be $2000<\/code><\/pre>\n<p>\u042e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442 \u043c\u043e\u0433 \u0431\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"dart\">group('Given 1000 coins with a total investment of \\$1000 ', () {   const coinAmount = 1000.0;   const totalInvestment = 1000.0;    group('\\nWhen coin price raise up to \\$2', () {     late PnlCalculatorResult pnl;     setUp(() {       pnl = PnlCalculator.calculate(         coinAmount: coinAmount,         totalInvestments: totalInvestment,         currentPrice: 2,       );     });     test('\\nThen PNL % should be 100%', () {       expect(pnl.percent, 100);     });      test('\\n    And PNL value should be \\$1000', () {       expect(pnl.value, 1000);     });      test('\\n    And holding value should be \\$2000', () {       expect(pnl.holdingValue, 2000);     });   }); });<\/code><\/pre>\n<p>\u0418 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043c\u044b \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438, \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u0442\u0430\u043a\u043e\u0433\u043e:<\/p>\n<pre><code>\u2713 Given 1000 coins with a total investment of $1000   When coin price raise up to $2  Then PNL % should be 100% \u2713 Given 1000 coins with a total investment of $1000   When coin price raise up to $2      And PNL value should be $1000 \u2713 Given 1000 coins with a total investment of $1000   When coin price raise up to $2      And holding value should be $2000<\/code><\/pre>\n<p>\u041a\u0430\u043a\u0438\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b c \u044d\u0442\u0438\u043c \u0442\u0435\u0441\u0442\u043e\u043c \u0438 \u043e\u0442\u0447\u0435\u0442\u043e\u043c?<\/p>\n<p>&#8212; \u041a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430 \u0442\u044f\u0436\u0435\u043b\u043e \u0447\u0438\u0442\u0430\u0442\u044c. \u0422\u0443\u0442 \u0435\u0441\u0442\u044c \u0438 <code>group<\/code>, <code>setUp<\/code> \u0438 <code>test<\/code> \u0442\u0435\u0440\u043c\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0438 \u043c\u0435\u0448\u0430\u044e\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043e \u0447\u0435\u043c \u0442\u0435\u0441\u0442. \u0410 BDD \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u043b\u043e\u0432 \u0438 \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043e\u043a, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u0439 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0434\u0430\u0436\u0435 \u0434\u0430\u043b\u0435\u043a\u0438\u0439 \u043e\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0435\u0441\u0442 \u0438 \u043f\u043e\u043d\u044f\u0442\u044c \u043e \u0447\u0435\u043c \u043e\u043d.<\/p>\n<p>&#8212; \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043e\u0442\u0447\u0435\u0442, \u0442\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u043c \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u043b\u043e\u043a\u043e\u0432 <code>GIVEN<\/code> \u0438 <code>WHEN<\/code>, \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0430 <code>THEN<\/code> \u0438 <code>AND<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0447\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0440\u043e\u0432\u043d\u043e \u0442\u0430\u043a, \u043a\u0430\u043a \u0441\u0430\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439. \u0418 <code>\\n<\/code> \u0441 \u0442\u0430\u0431\u0443\u043b\u044f\u0446\u0438\u0435\u0439 \u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u0430 \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u0440\u0442\u044f\u0442 \u043a\u043e\u0434 \u0441\u0430\u043c\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430.<\/p>\n<p>\u0418 \u0442\u0443\u0442 \u043a \u043d\u0430\u043c \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 Dart-\u043f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/pub.dev\/packages\/given_when_then_unit_test\" rel=\"noopener noreferrer nofollow\">given_when_then_unit_test<\/a>. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e, \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"dart\">given('1000 coins with a total investment of \\$1000', () {   const coinAmount = 1000.0;   const totalInvestment = 1000.0;    when('coin price raise up to \\$2', () {     late PnlCalculatorResult pnl;     before(() {       pnl = PnlCalculator.calculate(         coinAmount: coinAmount,         totalInvestments: totalInvestment,         currentPrice: 2,       );     });      then('PNL % should be 100%', () => expect(pnl.percent, 100), and: {       'PNL value should be \\$1000': () => expect(pnl.value, 1000),       'holding value should be \\$2000': () => expect(pnl.holdingValue, 2000),     });   }); });<\/code><\/pre>\n<p>\u0418 \u043e\u0442\u0447\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f \u0438 \u0441\u0430\u043c \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430 <s>\u0442\u043e\u0447\u043d\u043e<\/s> \u043f\u043e\u0447\u0442\u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f.<\/p>\n<pre><code>Given 1000 coins with a total investment of $1000  When coin price raise up to $2  Then PNL % should be 100%   And PNL value should be $1000   And holding value should be $2000<\/code><\/pre>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/62839e6415db00b4622648b2\" data-style=\"\" id=\"62839e6415db00b4622648b2\" width=\"\"><\/div>\n<h2>Shouldly<\/h2>\n<blockquote>\n<p>\u0438 \u0441\u0430\u043c \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430 <s>\u0442\u043e\u0447\u043d\u043e<\/s> \u043f\u043e\u0447\u0442\u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f.<\/p>\n<\/blockquote>\n<p>&#8230;\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0432\u043e\u0442 \u044d\u0442\u0438\u0445 \u0441\u0442\u0440\u043e\u043a \u0441 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"dart\">then('PNL % should be 100%', () => expect(pnl.percent, 100), and: {   'PNL value should be \\$1000': () => expect(pnl.value, 1000),   'holding value should be \\$2000': () => expect(pnl.holdingValue, 2000), });<\/code><\/pre>\n<p>\u041d\u043e \u044d\u0442\u043e \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0442\u043e\u0440\u043e\u0433\u043e Dart-\u043f\u0430\u043a\u0435\u0442\u0430 <a href=\"https:\/\/pub.dev\/packages\/shouldly\" rel=\"noopener noreferrer nofollow\">shouldly<\/a>. \u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0449\u0435 \u0438 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0418 \u044d\u0442\u0438 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u043a\u0430\u043a:<\/p>\n<pre><code>expect(pnl.percent, 100)       => pnl.percent.should.be(100) expect(pnl.value, 1000)        => pnl.value.should.be(1000) expect(pnl.holdingValue, 2000) => pnl.holdingValue.should.be(2000)<\/code><\/pre>\n<p>\u0418 \u0442\u0430\u043a\u0438\u043c \u0432\u043e\u0442 \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f:<\/p>\n<pre><code class=\"dart\">then(   'PNL % should be 100%', () => pnl.percent.should.be(100),   and: {     'PNL value should be \\$1000': () => pnl.value.should.be(1000),     'holding value should be \\$2000': () => pnl.holdingValue.should.be(2000),   }, );<\/code><\/pre>\n<h2>\u0411\u043e\u043b\u044c\u0448\u0435 \u0444\u0438\u0448\u0435\u043a<\/h2>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0447\u0438\u043d, \u043f\u043e\u0447\u0435\u043c\u0443 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>shouldly<\/code>.  <\/p>\n<p><strong>\u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u043e\u0432\u0430\u043b\u0430 \u0442\u0435\u0441\u0442\u0430<\/strong><\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0434\u0432\u0430 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u043d\u0435 \u0440\u0430\u0432\u043d\u044b, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043f\u0440\u0438\u0447\u0438\u043d\u0443 \u043e \u043f\u0440\u043e\u0432\u0430\u043b\u0435 \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code>Expected: &lt;10>   Actual: &lt;100><\/code><\/pre>\n<p>\u041a\u0442\u043e \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 100 \u0438 10? \u041a\u0430\u043a\u0438\u0435 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0447\u0442\u043e \u0442\u0430\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442\u0441\u044f? \u0423 \u043d\u0430\u0441 \u043d\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u0422\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u043b\u043e\u0433\u0430\u0445 \u0438 \u043d\u0430\u0439\u0442\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0430, \u0442\u043e \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c. \u0410 \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u0442\u0435\u0441\u0442\u0435 \u0434\u0432\u0430 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f, \u0447\u0435\u0433\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0438 \u043e \u0447\u0435\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u0432 <a href=\"https:\/\/www.youtube.com\/watch?v=FWra0ORVios&amp;t=1632s\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u043c \u0432\u0438\u0434\u0435\u043e<\/a>.<\/p>\n<pre><code class=\"dart\">test('many expectations in single test', () {   expect(hero.health, 100);   expect(hero.strength, 100); });<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0443\u0437\u043d\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043d\u0435\u0432\u0435\u0440\u043d\u043e? \u041d\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u044f\u0442\u044c \u0442\u0430\u043a\u0438 \u0432 \u043b\u043e\u0433\u0430\u0445 \u043f\u043e\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0438 \u043d\u0430\u0439\u0442\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0443. \u0418\u043b\u0438 \u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>reason<\/code> \u0432 <code>expect<\/code>:<\/p>\n<pre><code>expect(hero.health, 100, reason: 'Health in the beginning should be 100'); expect(hero.strength, 100);<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0432\u0430\u043b\u0430 \u0442\u0435\u0441\u0442\u0430 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e. \u041d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u043d\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e.<\/p>\n<pre><code>Expected: &lt;100>   Actual: &lt;10> Health in the beginning should be 100<\/code><\/pre>\n<p>\u0421 <code>shouldly<\/code> \u044d\u0442\u043e \u0436\u0435 \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>hero.health.should.be(100);<\/code><\/pre>\n<p>\u0418 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u043f\u0440\u043e\u0432\u0430\u043b\u0435 \u0442\u0435\u0441\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code>Expected `int`     should be 100     but was 10<\/code><\/pre>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 <code>.as('some alias').<\/code>:<\/p>\n<pre><code>hero.health.should.as('hero\\'s health').be(100);<\/code><\/pre>\n<p>\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0435 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043f\u0440\u043e\u0432\u0430\u043b\u0430 \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code>Expected `hero's health`     should be 100     but was 10<\/code><\/pre>\n<p>\u0416\u0430\u043b\u044c, \u0447\u0442\u043e \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f \u0432 Dart \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435 \u0442\u0430\u043a \u043a\u0430\u043a \u0432 .NET. \u0412 .NET \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043e\u0439 \u0438 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435 \u0438 \u043d\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>.as('some alias').<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e <a href=\"https:\/\/docs.shouldly.io\/documentation\/equality\/shouldbe\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>. \u041d\u043e \u043a\u0442\u043e \u0437\u043d\u0430\u0435\u0442, \u043c\u043e\u0436\u0435\u0442 \u0442\u0430\u043a\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u0435\u0449\u0451 \u0432 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f\u0445 Dart&#8217;\u0430.<\/p>\n<p><strong>\u041f\u0443\u0442\u0430\u043d\u0438\u0446\u0430 actual \u0441 expected<\/strong><\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>expect<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 <code>matcher<\/code> (\u0438\u043b\u0438 <code>expected<\/code>), \u0430 \u0434\u0440\u0443\u0433\u043e\u0439 <code>actual<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c, \u0441\u043a\u0430\u0436\u0438\u0442\u0435, \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>expect<\/code>, \u0430 \u043a\u0430\u043a\u043e\u0439 \u0432\u0442\u043e\u0440\u044b\u043c?<\/p>\n<pre><code class=\"dart\">final actual = 0; final expected = 0;  expect(actual, expected); expect(expected, actual);<\/code><\/pre>\n<p>\u041e\u0431\u0430 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b\u0445 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0439\u0434\u0443\u0442.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u0430\u0442\u0447\u0435\u0440 <code>isZero<\/code>.<\/p>\n<pre><code class=\"dart\">final actual = 0;  expect(actual, isZero); expect(isZero, actual);<\/code><\/pre>\n<p>\u0414\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0442\u0435\u0441\u0442\u0430 \u0432\u0440\u043e\u0434\u0435 \u0432\u0441\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0445\u043e\u0440\u043e\u0448\u043e &#8212; \u043e\u0448\u0438\u0431\u043e\u043a \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043d\u0435\u0442.<\/p>\n<p>\u041d\u041e! \u0412\u0442\u043e\u0440\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u0442, \u0438 \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0447\u0435\u043d\u044c \u0441\u0442\u0440\u0430\u043d\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<pre><code>Expected: &lt;0>   Actual: a value equal to &lt;0><\/code><\/pre>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6283a0adea15664f98adaa38\" data-style=\"\" id=\"6283a0adea15664f98adaa38\" width=\"\"><\/div>\n<p><strong>\u041a\u0443\u0447\u043a\u0430 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0439<\/strong><\/p>\n<p>\u0412 <code>shouldly<\/code> \u043d\u0435 \u0441\u0432\u0430\u043b\u0435\u043d\u043d\u043e \u0432\u0441\u0451 \u0432 \u043e\u0434\u043d\u0443 \u043a\u0443\u0447\u0443, \u0432\u0441\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043c\u0430\u0442\u0447\u0435\u0440\u044b.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0442\u0438\u043f \u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0441 <code>expect<\/code>:<\/p>\n<pre><code class=\"dart\">expect(0, isEmpty);<\/code><\/pre>\n<p>\u0412 <code>shouldy<\/code> \u0432\u0441\u0451 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0438\u043f\u0430 \u0442\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<figure class=\"float bordered full-width\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u2139\ufe0f \u0414\u0440\u0443\u0433\u0438\u0435 \u0444\u0438\u0447\u0438 \u043a\u0430\u043a<\/p>\n<p>&#8212; <a href=\"https:\/\/pub.dev\/packages\/shouldly#custom-matchers\" rel=\"noopener noreferrer nofollow\">Custom matchers<\/a>,<\/p>\n<p>&#8212; <a href=\"https:\/\/pub.dev\/packages\/shouldly#conjunctions\" rel=\"noopener noreferrer nofollow\">Conjunctions<\/a>,<\/p>\n<p>&#8212; <a href=\"https:\/\/pub.dev\/packages\/shouldly#satisfyallconditions\" rel=\"noopener noreferrer nofollow\">SatisfyAllConditions<\/a> <\/p>\n<p>&#8212; \u0438 \u0434\u0440. \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435  <a href=\"https:\/\/pub.dev\/packages\/shouldly\" rel=\"noopener noreferrer nofollow\">\u0441\u0430\u043c\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0430 pub.dev<\/a><\/p>\n<h2>\u0422\u0435\u0441\u0442-\u043a\u0435\u0439\u0441\u044b<\/h2>\n<p>\u0412 \u0438\u0434\u0435\u0430\u043b\u0435, \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u0443\u0447\u0430\u0435\u0432 (<strong>\u0442\u0435\u0441\u0442-\u043a\u0435\u0439\u0441\u043e\u0432<\/strong>). \u0418 \u043f\u0440\u0438<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-333423","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/333423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=333423"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/333423\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=333423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=333423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=333423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}