{"id":796,"date":"2024-08-29T23:41:28","date_gmt":"2024-08-30T06:41:28","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/?p=796"},"modified":"2024-08-29T23:41:28","modified_gmt":"2024-08-30T06:41:28","slug":"%e4%bd%bf%e7%94%a8-mstest-analyzers-%e5%a2%9e%e5%bc%ba%e6%82%a8%e7%9a%84%e6%b5%8b%e8%af%95%e4%bd%93%e9%aa%8c","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/%e4%bd%bf%e7%94%a8-mstest-analyzers-%e5%a2%9e%e5%bc%ba%e6%82%a8%e7%9a%84%e6%b5%8b%e8%af%95%e4%bd%93%e9%aa%8c\/","title":{"rendered":"\u4f7f\u7528 MSTest.Analyzers \u589e\u5f3a\u60a8\u7684\u6d4b\u8bd5\u4f53\u9a8c"},"content":{"rendered":"<p style=\"text-align: center;\"><em>\u672c\u7bc7\u7ffb\u8bd1\u4e8eJakub Jare\u0161\u7684<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/supercharge-your-testing-experience-with-ms-test-analyzers\/\">Supercharge your testing experience with MSTest.Analyzers &#8211; .NET Blog (microsoft.com)<\/a>\u00a0<\/em><\/p>\n<p><span data-contrast=\"auto\">MSTest <\/span><span data-contrast=\"auto\">\u9644\u5e26\u4e00\u7ec4\u5206\u6790\u5668\uff0c\u7528\u4e8e\u68c0\u67e5\u60a8\u7684\u6d4b\u8bd5\u4ee3\u7801\u5e76\u6307\u51fa\u5e38\u89c1\u7684\u9519\u8bef\u548c\u9677\u9631\u3002\u8fd9\u4e9b\u9519\u8bef\u53ef\u80fd\u5f88\u5fae\u5999\uff0c<\/span><span data-contrast=\"auto\">\u5e76\u5bfc\u81f4\u6d4b\u8bd5\u6846\u67b6\u5b8c\u5168\u5ffd\u7565\u60a8\u7684\u6d4b\u8bd5<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u6211\u4eec\u4ece<\/span><span data-contrast=\"auto\"> 3.2.0 <\/span><span data-contrast=\"auto\">\u7248\u672c\u5c31\u5f00\u59cb\u63d0\u4f9b\u8fd9\u4e9b\u5206\u6790\u5668\u4e86\uff0c\u4f46\u5728\u6700\u65b0\u7684<\/span><span data-contrast=\"auto\"> 3.5.1 <\/span><span data-contrast=\"auto\">\u7248\u672c\u4e2d\uff0c\u6211\u4eec\u6dfb\u52a0\u4e86\u4e00\u4e9b\u6211\u4eec\u8ba4\u4e3a\u60a8\u4e0d\u5e94\u9519\u8fc7\u7684\u5206\u6790\u5668<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<h3><b><span data-contrast=\"auto\">\u9057\u6f0f\u7684\u6d4b\u8bd5<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u662f\u5f53\u60a8\u5fd8\u8bb0\u5728\u7c7b\u4e0a\u6dfb\u52a0<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> [TestClass] <\/span><span data-contrast=\"auto\">\u65f6\u3002<\/span><span data-contrast=\"auto\">MSTest <\/span><span data-contrast=\"auto\">\u5c06\u65e0\u6cd5\u77e5\u9053\u7c7b\u4e2d\u6709\u6d4b\u8bd5\uff0c\u4e5f\u4e0d\u4f1a\u8fd0\u884c\u5b83\u4eec<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">public class MyTests\r\n\r\n{\r\n    [TestMethod]\r\n    public async Task TestMethod1()\r\n    {\r\n      Assert.Fail();\r\n    }\r\n}<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u5982\u679c\u6ca1\u6709<\/span><span data-contrast=\"auto\"> MSTest.Analyzers<\/span><span data-contrast=\"auto\">\uff0c\u6b64\u4ee3\u7801\u5728\u6784\u5efa\u65f6\u4e0d\u4f1a\u51fa\u73b0\u8b66\u544a\u6216\u4fe1\u606f\u63d0\u793a\u3002\u8fd0\u884c\u6d4b\u8bd5\u65f6\u4e5f\u4e0d\u4f1a\u51fa\u73b0\u6d4b\u8bd5\u5931\u8d25\u7684\u60c5\u51b5\u3002\u7531\u4e8e\u7c7b\u4e0a\u6ca1\u6709<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> [TestClass] <\/span><span data-contrast=\"auto\">\u5c5e\u6027\uff0c<\/span><span data-contrast=\"auto\">MSTest <\/span><span data-contrast=\"auto\">\u4f1a\u51fa\u4e8e\u6027\u80fd\u539f\u56e0\u8df3\u8fc7\u6574\u4e2a\u7c7b\uff0c\u5e76\u4e14\u60a8\u7684\u6d4b\u8bd5\u5c06\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u627e\u5230<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u4f46\u662f\u4f7f\u7528\u5206\u6790\u5668\u65f6\u60a8\u4f1a\u5728\u6784\u5efa\u8fc7\u7a0b\u4e2d\u6536\u5230\u4e00\u6761\u4fe1\u606f\u63d0\u793a<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2024\/08\/info-1.png\" alt=\"Info message for MSTEST0030 shown in Visual Studio Error List\" \/><\/span><\/p>\n<p><span data-contrast=\"auto\">\u6211\u4eec\u5efa\u8bae\u5c06\u6b64\u4fe1\u606f\u63d0\u793a\u5347\u7ea7\u4e3a\u8b66\u544a\uff0c\u751a\u81f3\u662f\u6784\u5efa\u9519\u8bef\u3002\u53ef\u4ee5\u901a\u8fc7\u5728<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> .editorconfig <\/span><span data-contrast=\"auto\">\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u8fd9\u884c\u4ee3\u7801\u6765\u5b9e\u73b0<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">[*.cs]\r\n# MSTEST0030: Type containing '[TestMethod]' should be marked with '[TestClass]'\r\ndotnet_diagnostic.MSTEST0030.severity = warning<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2024\/08\/warning-1.png\" alt=\"Warning message for MSTEST0030 shown in Visual Studio Error List\" \/><\/p>\n<h3><b><span data-contrast=\"auto\">\u4e3a\u4ec0\u4e48\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u8fd9\u4e0d\u662f\u8b66\u544a\uff1f<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">\u60a8\u53ef\u80fd\u4f1a\u95ee\u4e3a\u4ec0\u4e48<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> MSTEST0030 <\/span><span data-contrast=\"auto\">\u9ed8\u8ba4\u662f\u4e00\u6761\u4fe1\u606f\u63d0\u793a\u800c\u4e0d\u662f\u9ed8\u8ba4\u7684\u8b66\u544a\u3002\u539f\u56e0\u662f\u6211\u4eec\u4e0d\u80fd\u5728<\/span><span data-contrast=\"auto\"> MSTest v3 <\/span><span data-contrast=\"auto\">\u4e2d\u5f15\u5165\u91cd\u5927\u53d8\u66f4<\/span><span data-contrast=\"auto\">\uff0c<\/span><span data-contrast=\"auto\">\u800c\u4e0a\u8ff0\u4ee3\u7801\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u6a21\u5f0f\uff0c\u7528\u4e8e\u4ece\u57fa\u7c7b\u91cd\u7528\u6d4b\u8bd5\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">public class MyTestsBase\r\n{\r\n    [TestMethod]\r\n    public async Task CommonTestMethod()\r\n    {\r\n    }\r\n}\r\n\r\n[TestClass]\r\npublic class MyTests : MyTestsBase\r\n{\r\n    [TestMethod]\r\n    public async Task TestMethod1()\r\n    {\r\n      Assert.Fail();\r\n    }\r\n}<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6d4b\u8bd5<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> CommonTestMethod<\/span> <\/span><span data-contrast=\"auto\">\u4e0d\u4f1a\u4ece<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> MyTestsBase<\/span> <\/span><span data-contrast=\"auto\">\u8fd0\u884c\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> [TestClass] <\/span><span data-contrast=\"auto\">\u5c5e\u6027\uff0c\u4f46\u5b83\u4f1a\u88ab\u7ee7\u627f\u5230<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> MyTests <\/span><span data-contrast=\"auto\">\u4e2d\u5e76\u5728\u90a3\u91cc\u8fd0\u884c<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u6211\u4eec<strong>\u4e0d\u63a8\u8350<\/strong>\u8fd9\u79cd\u6a21\u5f0f\u3002\u76f8\u53cd\uff0c\u5982\u679c\u60a8\u4e0d\u60f3\u4ece\u4e2d\u8fd0\u884c\u6d4b\u8bd5\uff0c\u6211\u4eec\u5efa\u8bae\u59cb\u7ec8\u7528<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> [TestClass] <\/span><span data-contrast=\"auto\">\u6807\u8bb0\u7c7b\uff0c\u5e76\u5c06\u57fa\u7c7b\u8bbe\u4e3a\u62bd\u8c61\u7c7b<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">[TestClass]\r\npublic abstract class MyTestsBase\r\n{\r\n    [TestMethod]\r\n    public async Task CommonTestMethod()\r\n    {\r\n    }\r\n}\r\n\r\n[TestClass]\r\npublic class MyTests : MyTestsBase\r\n{\r\n    [TestMethod]\r\n    public async Task TestMethod1()\r\n    {\r\n      Assert.Fail();\r\n    }\r\n}<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u8fd9\u79cd\u65b9\u6cd5\u4e0e\u4e0a\u8ff0\u65b9\u6cd5\u7c7b\u4f3c\uff0c\u4f46\u60a8\u53ef\u4ee5\u6e05\u695a\u5730\u5411\u5206\u6790\u5668\u548c\u6d4b\u8bd5\u6846\u67b6\u8bf4\u660e<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">\u202fabstract<\/span><span data-contrast=\"auto\">\u57fa\u7c7b\u4e2d\u5305\u542b\u5171\u4eab\u903b\u8f91\uff0c\u5e76\u4e14\u4e0d\u5e94\u8be5\u81ea\u884c\u8fd0\u884c<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<h3><b><span data-contrast=\"auto\">AssemblyInitialize <\/span><\/b><b><span data-contrast=\"auto\">\u683c\u5f0f\u9519\u8bef<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">\u53e6\u4e00\u4e2a\u6709\u7528\u7684\u5206\u6790\u5668\u7684\u4f8b\u5b50\u662f\u4fee\u590d<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> [AssemblyInitialize] <\/span><span data-contrast=\"auto\">\u7684\u7b7e\u540d\uff0c\u4e3a\u7a0b\u5e8f\u96c6\u4e2d\u7684\u6240\u6709\u6d4b\u8bd5\u8fdb\u884c\u4e00\u6b21\u6027\u8bbe\u7f6e<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u6211\u4e0d\u77e5\u9053\u60a8\u662f\u5426\u6709\u540c\u611f\uff0c\u4f46\u6211\u8bb0\u4e0d\u4f4f\u8fd9\u4e2a\u65b9\u6cd5\u7684\u7b7e\u540d\u3002\u5f53\u6211\u51fa\u9519\u65f6\uff0c\u6211\u7684\u6d4b\u8bd5\u6839\u672c\u5c31\u65e0\u6cd5\u8fd0\u884c\u3002\u8fd9\u5728<\/span><span data-contrast=\"auto\"> Visual Studio <\/span><span data-contrast=\"auto\">\u4e2d\u5c24\u5176\u4ee4\u4eba\u70e6\u607c\uff0c\u56e0\u4e3a\u6d4b\u8bd5\u4f1a\u4e00\u76f4\u4fdd\u6301\u84dd\u8272\uff0c\u800c\u6211\u9700\u8981\u67e5\u770b\u6d4b\u8bd5\u8f93\u51fa\u624d\u80fd\u627e\u5230\u539f\u56e0\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u4f46\u662f\u4f7f\u7528\u5206\u6790\u5668\uff0c\u6211\u53ef\u4ee5\u8f7b\u677e\u627e\u51fa\u9519\u8bef\uff0c\u751a\u81f3\u53ef\u4ee5\u5c06\u81ea\u52a8\u4fee\u590d\u5e94\u7528\u4e8e\u6211\u7684\u4ee3\u7801<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u5728\u8fd9\u91cc\u6211\u7f16\u5199\u4e00\u4e2a\u540d\u4e3a<\/span><span data-contrast=\"auto\">Setup<\/span><span data-contrast=\"auto\">\u7684\u65b9\u6cd5<\/span><span data-contrast=\"auto\">\uff0cVisualStudio <\/span><span data-contrast=\"auto\">\u4f1a\u5728\u5176\u4e0b\u5212\u7ebf\u5904\u6dfb\u52a0\u8b66\u544a\uff0c\u7136\u540e\u6211\u6309\u4e0b<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> Ctrl+. <\/span><span data-contrast=\"auto\">\u67e5\u770b\u81ea\u52a8\u4fee\u590d\u5e76\u5e94\u7528\u5b83<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">[TestClass]\r\npublic class MyTests\r\n{\r\n  [AssemblyInitialize]\r\n  public void Setup()\r\n  {\r\n  }\r\n}<\/code><\/pre>\n<p><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2024\/08\/warning-2.png\" alt=\"Warning message for MSTEST0012 shown in Visual Studio Error List\" \/><\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2024\/08\/code-fix.png\" alt=\"Fixing signature via lightbulb menu\" \/><\/p>\n<p><span data-contrast=\"auto\">\u5c06\u6211\u7684\u4ee3\u7801\u4fee\u590d\u4e3a\u6d4b\u8bd5\u6846\u67b6\u53ef\u4ee5\u8bc6\u522b\u7684\u6b63\u786e\u683c\u5f0f<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\"> [TestClass]\r\n public class MyTests\r\n {\r\n     [AssemblyInitialize]\r\n     public static void Setup(TestContext context)\r\n     {\r\n     }\r\n }<\/code><\/pre>\n<h3><b><span data-contrast=\"auto\">\u5b89\u88c5<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">\u5f00\u59cb\u4f7f\u7528<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> MSTest.Analyzers <\/span><span data-contrast=\"auto\">\u7684\u63a8\u8350\u65b9\u5f0f\u662f\u4f7f\u7528<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> MSTest<\/span> nuget <\/span><span data-contrast=\"auto\">\u5305\u6216<\/span><span data-contrast=\"auto\"> MSTest <\/span><span data-contrast=\"auto\">\u9879\u76ee<\/span><span data-contrast=\"auto\"> SDK<\/span><span data-contrast=\"auto\">\uff08\u7248\u672c<\/span><span data-contrast=\"auto\"> 3.2.0 <\/span><span data-contrast=\"auto\">\u6216\u66f4\u65b0\u7248\u672c\uff09<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/core\/testing\/unit-testing-mstest-getting-started\"><span data-contrast=\"none\">https:\/\/learn.microsoft.com\/dotnet\/core\/testing\/unit-testing-mstest-getting-started<\/span><\/a><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u8fd9\u4e9b\u5206\u6790\u5668\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5f15\u7528<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\">MSTest.Analyzers<\/span> NuGet<\/span><span data-contrast=\"auto\">\u5305\u5355\u72ec\u5b89\u88c5<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u6211\u4eec\u8877\u5fc3\u5efa\u8bae\u6240\u6709\u4f7f\u7528<\/span><span data-contrast=\"auto\"> MSTest <\/span><span data-contrast=\"auto\">\u7684\u9879\u76ee\u5347\u7ea7\u5230<\/span><span data-contrast=\"auto\"> 3.2.0 <\/span><span data-contrast=\"auto\">\u53ca\u66f4\u65b0\u7248\u672c\uff0c\u5e76\u542f\u7528\u8fd9\u4e9b\u5206\u6790\u5668<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<h3><b><span data-contrast=\"auto\">\u603b\u7ed3<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">\u672c\u6587\u4e2d\u5c55\u793a\u7684\u4e24\u4e2a\u5206\u6790\u5668\u662f\u6211\u5728\u65e5\u5e38\u5de5\u4f5c\u4e2d\u89c9\u5f97\u6700\u6709\u7528\u7684\u5206\u6790\u5668\u3002\u4f46\u8fd8\u6709\u66f4\u591a\u5176\u4ed6\u7684\u5206\u6790\u5668\uff0c\u4f8b\u5982<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:860,&quot;335559991&quot;:440,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"auto\">MSTEST0003<\/span><span data-contrast=\"auto\">\uff0c\u786e\u4fdd\u60a8\u7684\u6d4b\u8bd5\u65b9\u6cd5\u5177\u6709\u6b63\u786e\u7684\u7b7e\u540d\uff0c\u4f8b\u5982\u662f<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">public<\/span><span data-contrast=\"auto\">\uff0c\u800c\u4e0d\u662f<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\">async void<\/span>\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:860,&quot;335559991&quot;:440,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><span data-contrast=\"auto\">MSTEST0001<\/span><span data-contrast=\"auto\">\uff0c\u5efa\u8bae\u542f\u7528\u6d4b\u8bd5\u5e76\u884c\u5316\uff0c\u56e0\u4e3a\u6211\u4eec\u5df2\u7ecf\u770b\u5230\u591a\u4e2a\u6d4b\u8bd5\u57fa\u7840\u901a\u8fc7\u8fd9\u6837\u505a\u663e\u8457\u51cf\u5c11\u6d4b\u8bd5\u6267\u884c\u65f6\u95f4\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:860,&quot;335559991&quot;:440,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"3\" data-aria-level=\"1\"><span data-contrast=\"auto\">MSTEST0017<\/span><span data-contrast=\"auto\">\uff0c\u786e\u4fdd\u60a8\u4ee5\u6b63\u786e\u7684\u987a\u5e8f\u5c06\u53c2\u6570\u4f20\u9012\u7ed9\u65ad\u8a00\uff0c\u4ee5\u907f\u514d\u6df7\u6dc6\u6d4b\u8bd5\u5931\u8d25\u6d88\u606f\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-contrast=\"auto\">\u8fd8\u6709<\/span><span data-contrast=\"auto\"> 32 <\/span><span data-contrast=\"auto\">\u6761\u89c4\u5219\uff0c\u5206\u4e3a\u8bbe\u8ba1\u3001\u6027\u80fd\u548c\u4f7f\u7528\u7c7b\u522b\u3002\u5e2e\u52a9\u60a8\u7f16\u5199\u683c\u5f0f\u6b63\u786e<\/span><span data-contrast=\"auto\">\u3001<\/span><span data-contrast=\"auto\">\u9ad8\u6027\u80fd\u4e14\u65e0\u9519\u8bef\u7684\u6d4b\u8bd5\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/core\/testing\/mstest-analyzers\/overview\"><span data-contrast=\"none\">https:\/\/learn.microsoft.com\/dotnet\/core\/testing\/mstest-analyzers\/overview<\/span><\/a><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u6211\u4eec\u4e00\u76f4\u5728\u5bfb\u627e\u6539\u8fdb\u8fd9\u4e9b\u5206\u6790\u5668\u6216\u60a8\u7f3a\u5c11\u7684\u65b0\u5206\u6790\u5668\u7684\u65b9\u6cd5\u3002\u6211\u4eec\u6b22\u8fce\u60a8\u5728\u6211\u4eec\u7684\u5b58\u50a8\u5e93<\/span> <a href=\"https:\/\/github.com\/microsoft\/testfx\/issues\"><span data-contrast=\"auto\">microsoft\/<\/span><span data-contrast=\"none\">testfx<\/span><\/a> <span data-contrast=\"auto\">\u4e0a\u5206\u4eab\u60a8\u7684\u53cd\u9988\u3001\u5206\u6790\u5668\u7684\u521b\u610f\u4ee5\u53ca\u60a8\u7684\u4f7f\u7528\u4f53\u9a8c\u3002<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u7ffb\u8bd1\u4e8eJakub Jare\u0161\u7684Supercharge your testing experience with MSTest.Analyzers &#8211; .NET Blog (microsoft.com)\u00a0 MSTest \u9644\u5e26\u4e00\u7ec4\u5206\u6790\u5668\uff0c\u7528\u4e8e\u68c0\u67e5\u60a8\u7684\u6d4b\u8bd5\u4ee3\u7801\u5e76\u6307\u51fa\u5e38\u89c1\u7684\u9519\u8bef\u548c\u9677\u9631\u3002\u8fd9\u4e9b\u9519\u8bef\u53ef\u80fd\u5f88\u5fae\u5999\uff0c\u5e76\u5bfc\u81f4\u6d4b\u8bd5\u6846\u67b6\u5b8c\u5168\u5ffd\u7565\u60a8\u7684\u6d4b\u8bd5\u3002\u00a0 \u6211\u4eec\u4ece 3.2.0 \u7248\u672c\u5c31\u5f00\u59cb\u63d0\u4f9b\u8fd9\u4e9b\u5206\u6790\u5668\u4e86\uff0c\u4f46\u5728\u6700\u65b0\u7684 3.5.1 \u7248\u672c\u4e2d\uff0c\u6211\u4eec\u6dfb\u52a0\u4e86\u4e00\u4e9b\u6211\u4eec\u8ba4\u4e3a\u60a8\u4e0d\u5e94\u9519\u8fc7\u7684\u5206\u6790\u5668\u3002\u00a0 \u9057\u6f0f\u7684\u6d4b\u8bd5\u00a0 \u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u662f\u5f53\u60a8\u5fd8\u8bb0\u5728\u7c7b\u4e0a\u6dfb\u52a0 [TestClass] \u65f6\u3002MSTest \u5c06\u65e0\u6cd5\u77e5\u9053\u7c7b\u4e2d\u6709\u6d4b\u8bd5\uff0c\u4e5f\u4e0d\u4f1a\u8fd0\u884c\u5b83\u4eec\uff1a\u00a0 public class MyTests { [TestMethod] public async Task TestMethod1() { Assert.Fail(); } } \u5982\u679c\u6ca1\u6709 MSTest.Analyzers\uff0c\u6b64\u4ee3\u7801\u5728\u6784\u5efa\u65f6\u4e0d\u4f1a\u51fa\u73b0\u8b66\u544a\u6216\u4fe1\u606f\u63d0\u793a\u3002\u8fd0\u884c\u6d4b\u8bd5\u65f6\u4e5f\u4e0d\u4f1a\u51fa\u73b0\u6d4b\u8bd5\u5931\u8d25\u7684\u60c5\u51b5\u3002\u7531\u4e8e\u7c7b\u4e0a\u6ca1\u6709 [TestClass] \u5c5e\u6027\uff0cMSTest \u4f1a\u51fa\u4e8e\u6027\u80fd\u539f\u56e0\u8df3\u8fc7\u6574\u4e2a\u7c7b\uff0c\u5e76\u4e14\u60a8\u7684\u6d4b\u8bd5\u5c06\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u627e\u5230\u3002\u00a0 \u4f46\u662f\u4f7f\u7528\u5206\u6790\u5668\u65f6\u60a8\u4f1a\u5728\u6784\u5efa\u8fc7\u7a0b\u4e2d\u6536\u5230\u4e00\u6761\u4fe1\u606f\u63d0\u793a\uff1a\u00a0 \u6211\u4eec\u5efa\u8bae\u5c06\u6b64\u4fe1\u606f\u63d0\u793a\u5347\u7ea7\u4e3a\u8b66\u544a\uff0c\u751a\u81f3\u662f\u6784\u5efa\u9519\u8bef\u3002\u53ef\u4ee5\u901a\u8fc7\u5728 .editorconfig \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u8fd9\u884c\u4ee3\u7801\u6765\u5b9e\u73b0\u00a0 [*.cs] # MSTEST0030: Type containing &#8216;[TestMethod]&#8217; should be marked with [&hellip;]<\/p>\n","protected":false},"author":97248,"featured_media":798,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[55,56],"class_list":["post-796","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet-ch","tag-mstest","tag-testing"],"acf":[],"blog_post_summary":"<p>\u672c\u7bc7\u7ffb\u8bd1\u4e8eJakub Jare\u0161\u7684Supercharge your testing experience with MSTest.Analyzers &#8211; .NET Blog (microsoft.com)\u00a0 MSTest \u9644\u5e26\u4e00\u7ec4\u5206\u6790\u5668\uff0c\u7528\u4e8e\u68c0\u67e5\u60a8\u7684\u6d4b\u8bd5\u4ee3\u7801\u5e76\u6307\u51fa\u5e38\u89c1\u7684\u9519\u8bef\u548c\u9677\u9631\u3002\u8fd9\u4e9b\u9519\u8bef\u53ef\u80fd\u5f88\u5fae\u5999\uff0c\u5e76\u5bfc\u81f4\u6d4b\u8bd5\u6846\u67b6\u5b8c\u5168\u5ffd\u7565\u60a8\u7684\u6d4b\u8bd5\u3002\u00a0 \u6211\u4eec\u4ece 3.2.0 \u7248\u672c\u5c31\u5f00\u59cb\u63d0\u4f9b\u8fd9\u4e9b\u5206\u6790\u5668\u4e86\uff0c\u4f46\u5728\u6700\u65b0\u7684 3.5.1 \u7248\u672c\u4e2d\uff0c\u6211\u4eec\u6dfb\u52a0\u4e86\u4e00\u4e9b\u6211\u4eec\u8ba4\u4e3a\u60a8\u4e0d\u5e94\u9519\u8fc7\u7684\u5206\u6790\u5668\u3002\u00a0 \u9057\u6f0f\u7684\u6d4b\u8bd5\u00a0 \u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u662f\u5f53\u60a8\u5fd8\u8bb0\u5728\u7c7b\u4e0a\u6dfb\u52a0 [TestClass] \u65f6\u3002MSTest \u5c06\u65e0\u6cd5\u77e5\u9053\u7c7b\u4e2d\u6709\u6d4b\u8bd5\uff0c\u4e5f\u4e0d\u4f1a\u8fd0\u884c\u5b83\u4eec\uff1a\u00a0 public class MyTests { [TestMethod] public async Task TestMethod1() { Assert.Fail(); } } \u5982\u679c\u6ca1\u6709 MSTest.Analyzers\uff0c\u6b64\u4ee3\u7801\u5728\u6784\u5efa\u65f6\u4e0d\u4f1a\u51fa\u73b0\u8b66\u544a\u6216\u4fe1\u606f\u63d0\u793a\u3002\u8fd0\u884c\u6d4b\u8bd5\u65f6\u4e5f\u4e0d\u4f1a\u51fa\u73b0\u6d4b\u8bd5\u5931\u8d25\u7684\u60c5\u51b5\u3002\u7531\u4e8e\u7c7b\u4e0a\u6ca1\u6709 [TestClass] \u5c5e\u6027\uff0cMSTest \u4f1a\u51fa\u4e8e\u6027\u80fd\u539f\u56e0\u8df3\u8fc7\u6574\u4e2a\u7c7b\uff0c\u5e76\u4e14\u60a8\u7684\u6d4b\u8bd5\u5c06\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u627e\u5230\u3002\u00a0 \u4f46\u662f\u4f7f\u7528\u5206\u6790\u5668\u65f6\u60a8\u4f1a\u5728\u6784\u5efa\u8fc7\u7a0b\u4e2d\u6536\u5230\u4e00\u6761\u4fe1\u606f\u63d0\u793a\uff1a\u00a0 \u6211\u4eec\u5efa\u8bae\u5c06\u6b64\u4fe1\u606f\u63d0\u793a\u5347\u7ea7\u4e3a\u8b66\u544a\uff0c\u751a\u81f3\u662f\u6784\u5efa\u9519\u8bef\u3002\u53ef\u4ee5\u901a\u8fc7\u5728 .editorconfig \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u8fd9\u884c\u4ee3\u7801\u6765\u5b9e\u73b0\u00a0 [*.cs] # MSTEST0030: Type containing &#8216;[TestMethod]&#8217; should be marked with [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts\/796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/users\/97248"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/comments?post=796"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts\/796\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/media\/798"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/media?parent=796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/categories?post=796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/tags?post=796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}