首页 新闻 会员 周边 捐助

.NET:寻找 FluentAssertions 的替代

0
悬赏园豆:30 [已解决问题] 解决于 2025-05-03 18:53

今天在升级 nuget 包时发现 FluentAssertions 从 8.0 版本开始针对商业使用收费了

Versions 8 and beyond are/will be free for open-source projects and non-commercial use, but commercial use requires a paid license. Check out the license page for more information.

详见 https://fluentassertions.com/releases/#license-change

需要找一个替代

dudu的主页 dudu | 高人七级 | 园豆:24728
提问于:2025-05-03 17:42
< >
分享
最佳答案
0

开源社区做了一个完美替代 —— AwesomeAssertions

FluentAssertions, up to version 7.x, was licensed under Apache 2.0. Starting with later versions, licensing changes introduced potential fees for developers.
In response to these changes, this community project was created.

只要把 nuget 包换成 AwesomeAssertions 就行,连命名空间都不需要修改

dotnet add package AwesomeAssertions

需要注意的一个地方,如果在针对 HttpResponseMessage 的测试中使用了 FluentAssertions,需要进行一些改动

The support for assertions on this type was removed in Awesome Assertions 8.0. If you need to do assertions like these, we recommend you adopt FluentAssertions.Web.

比如下面的测试用例

// Act
var client = app.GetTestClient();
var response = await client.GetAsync("/robots.txt");

// Assert
response.Should().BeSuccessful();

需要安装下面的 nuget 包

dotnet add package FluentAssertions.Web.v8

并改为

response.Should().Be200Ok();
dudu | 高人七级 |园豆:24728 | 2025-05-03 18:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册