{"id":757,"date":"2022-10-07T18:31:26","date_gmt":"2022-10-07T10:31:26","guid":{"rendered":"https:\/\/qaqaq.top\/?p=757"},"modified":"2022-11-27T12:39:55","modified_gmt":"2022-11-27T04:39:55","slug":"%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e4%b8%ad-%e5%8d%95%e5%85%83%e6%b5%8b%e8%af%95%e6%96%b9%e6%b3%95%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=757","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e2d)-\u5355\u5143\u6d4b\u8bd5\u65b9\u6cd5\u7684\u4f7f\u7528"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P303;\r\n\r\nimport java.util.Date;\r\n\r\nimport org.junit.Test;\r\n\r\n\/*\r\n * Java\u4e2d\u7684JUnit\u5355\u5143\u6d4b\u8bd5\r\n * \r\n * \u6b65\u9aa4\uff1a\r\n * 1. \u9009\u4e2d\u5f53\u524d\u5de5\u7a0b - \u53f3\u952e\u9009\u62e9\uff1abuild path - add libraries - JUnit 4 - \u4e0b\u4e00\u6b65\r\n * 2. \u521b\u5efaJava\u7c7b\uff0c\u8fdb\u884c\u5355\u5143\u6d4b\u8bd5\u3002\r\n * \t\t\u6b64\u65f6\u7684Java\u7c7b\u8981\u6c42\uff1a\u2460 \u6b64\u7c7b\u662fpublic\u7684 \u2461 \u6b64\u7c7b\u63d0\u4f9b\u516c\u5171\u7684\u65e0\u53c2\u7684\u6784\u9020\u5668\r\n * 3. \u6b64\u7c7b\u4e2d\u58f0\u660e\u5355\u5143\u6d4b\u8bd5\u65b9\u6cd5\u3002\r\n * \t\t\u6b64\u65f6\u7684\u5355\u5143\u6d4b\u8bd5\u65b9\u6cd5\uff1a\u65b9\u6cd5\u7684\u6743\u9650\u662fpublic,\u6ca1\u6709\u8fd4\u56de\u503c\uff0c\u6ca1\u6709\u5f62\u53c2\r\n * \r\n * 4. \u6b64\u5355\u5143\u6d4b\u8bd5\u65b9\u6cd5\u4e0a\u9700\u8981\u58f0\u660e\u6ce8\u89e3\uff1a@Test,\u5e76\u5728\u5355\u5143\u6d4b\u8bd5\u7c7b\u4e2d\u5bfc\u5165\uff1aimport org.junit.Test;\r\n * \r\n * 5. \u58f0\u660e\u597d\u5355\u5143\u6d4b\u8bd5\u65b9\u6cd5\u4ee5\u540e\uff0c\u5c31\u53ef\u4ee5\u5728\u65b9\u6cd5\u4f53\u5185\u6d4b\u8bd5\u76f8\u5173\u7684\u4ee3\u7801\u3002\r\n * \r\n * 6. \u5199\u5b8c\u4ee3\u7801\u4ee5\u540e\uff0c\u5de6\u952e\u53cc\u51fb\u5355\u5143\u6d4b\u8bd5\u65b9\u6cd5\u540d\uff0c\u90ae\u4ef6\uff1arun as - JUnit Test\r\n * \r\n * \u8bf4\u660e\uff1a\r\n * 1. \u5982\u679c\u6267\u884c\u7ed3\u679c\u6ca1\u6709\u4efb\u4f55\u5f02\u5e38\uff1a\u7eff\u6761\r\n * 2. \u5982\u679c\u6267\u884c\u7ed3\u679c\u51fa\u73b0\u5f02\u5e38\uff1a\u7ea2\u6761\r\n *\/\r\npublic class JUnitTest {\r\n\r\n\tint num = 10;\r\n\t\r\n\t@Test\r\n\tpublic void testEquals() {\r\n\t\tString s1 = \"MM\";\r\n\t\tString s2 = \"MM\";\r\n\t\tSystem.out.println(s1.equals(s2));\r\n\t\t\/\/ClassCastException\u7684\u5f02\u5e38\r\n\/\/\t\tObject obj = new String(\"GG\");\r\n\/\/\t\tDate date = (Date)obj;\r\n\t\tSystem.out.println(num);\r\n\t\tshow();\r\n\t}\r\n\t\r\n\tpublic void show() {\r\n\t\tnum = 20;\r\n\t\tSystem.out.println(\"show()....\");\r\n\t}\r\n\t\r\n\t@Test\r\n\tpublic void testToString() {\r\n\t\tString s2 = \"MM\";\r\n\t\tSystem.out.println(s2.toString());\r\n\t}\r\n\t\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-757","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/757"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=757"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/757\/revisions"}],"predecessor-version":[{"id":758,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/757\/revisions\/758"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}