Assert.IsEmpty已弃用,请求转换相关旧测试代码
解决Assert.IsEmpty弃用导致的CS0117错误
旧代码中的Assert.IsEmpty方法已被移除或重命名,导致编译报错CS0117 'Assert' does not contain a definition for 'IsEmpty'。根据你使用的.NET测试框架,可将代码替换为以下对应写法:
原代码
Testcase.axeResult = new AxeBuilder(Testcase.driver).Analyze(); Assert.IsEmpty(Testcase.axeResult.Violations);
替代方案
若使用xUnit
Testcase.axeResult = new AxeBuilder(Testcase.driver).Analyze(); Assert.Empty(Testcase.axeResult.Violations);
若使用NUnit
Testcase.axeResult = new AxeBuilder(Testcase.driver).Analyze(); // 推荐写法 Assert.That(Testcase.axeResult.Violations, Is.Empty); // 部分新版本NUnit仍兼容旧语法,也可直接使用 // Assert.IsEmpty(Testcase.axeResult.Violations);
若使用MSTest
Testcase.axeResult = new AxeBuilder(Testcase.driver).Analyze(); CollectionAssert.IsEmpty(Testcase.axeResult.Violations);
内容的提问来源于stack exchange,提问作者Big Ian
相关产品推荐
相关产品推荐

