小编shr*_*s35的帖子

如何在 Xunit 中使用 Assert.Throws 抛出异常

我正在尝试使用 Xunit 编写一个测试用例,其中我想检查我传递的文本是否不是预期的一个抛出异常,表示该值应该相同

这是我的代码

   [Theory]
   [InlineData("Goods","Goods")]
   [InlineData("Test","Goods")]
   public void Vehicle(string use,string expected)
   {
      // Arrange
      var risk= CreateRisk();
      var request = new Request();

      risk.Use = use;
      
      // Act
      Test().Mapping(risk, request);
      
      // Assert
     Assert.Throws<ArgumentException>(expected != "Goods" ? "Vehicle Use Should be with Goods": expected);
  
   }
Run Code Online (Sandbox Code Playgroud)

我不知道如何构建这个。提前致谢

c# xunit xunit.net .net-core

-1
推荐指数
1
解决办法
2447
查看次数

标签 统计

.net-core ×1

c# ×1

xunit ×1

xunit.net ×1