c# - 使用inlinedata时是否可以使用string.empty?

标签 c# unit-testing testing xunit.net

我在编写一些测试时想知道在使用 xUnit 测试时是否可以使用 @microsoft 声明的 string.isempty。 (见下文)

我是一名编程学生,我的老师建议尽可能使用@microsofts 已经定义的方法和常量。

我试过了,但似乎没有用,所以我想我可能做错了什么。

[Theory]
[InlineData(string.Empty)]
[InlineData(null)]
[InlineData("        ")]
[InlineData(" ")]
[InlineData(" someRandomText")]
// ... 
public void SetEmailaddress_WrongEmail_IllegalArgumentException(string data) // type of method that is being test, what kind of test, the expected outcome
   {
      //Assert
      Assert.Throws<ArgumentException>(() => _l.Emailaddress = data);
   }

提前致谢!

问候

最佳答案

它与测试无关,与属性有关。属性必须是编译时常量。

你可以去this找出为什么 string.empty""

相比不被视为常量的问题

关于c# - 使用inlinedata时是否可以使用string.empty?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55710151/

相关文章:

android - 如何测试按下按钮后文本字段是否留空?

shell - test -h 和 test -L 的区别

node.js - 断言正在破坏 Mocha 测试中的异步功能

c# - C#中的值类型类定义?

c# - IEnumerable 选择除字符串以外的所有内容

c# - Xamarin - Android - Visual Studio - 应用程序无法启动

c# - 从同一解决方案中另一个项目的 View 调用类库中的函数

PHPUnit 测试总是成功,无论是 $this->once() 还是 $this->never()?

iphone - 使用 MacRuby 测试 iPhone 应用程序?

c# - 更多验证条件