You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 20:19:55