Questions regarding fluent syntax design for assertions
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 20/100
- issue の種類
- ドキュメント
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- csharp
調査の方向性
まず、issue の例から参照されている assertion と constraint のドキュメント、特に Has、Contains、lambda ベースのマッチングを確認してください。ドキュメント化されている NUnit の構文と FluentAssertions のケースを比較し、そのうえで設計上の根拠、サポートされている同等機能、制限事項を明確にして、各例に曖昧さのないドキュメント化された回答があるようにしてください。
索引モデルが issue の本文から書いたものです。
説明
Coming from XUnit + FluentAssertions, I must say I love the TestCase feature of NUnit.
At the same time I feel that the assertion syntax seems all over the place. The fluent attempt mostly applies to reading the assertion, but definitely not to writing them, because Intellisense gives many false suggestions. And for the number of constraints listed in documentation the possibilities still seem rather limited.
There's nothing preventing me from using FluentAssertions, but I'm trying to understand the philosophy in the current assertion/constraint design in NUnit, especially since a lot of work seems to have gone into it.
First example of clunkiness: why does the Has class have a 'Length' and 'Count' which only work on classes with that exact property name? This leads to tests seemingly perfect by reading the code, but still failing at runtime because a collection was of an unexpected type. It's just confusing while there is a syntax that always works...
[Test]
public void Test_ItemCount()
{
var MyArray = new[] { 1, 2, 3 };
var MyCollection = new List<int> { 1, 2, 3, };
var MyEnumerable = Enumerable.Range(1, 3);
// NUnit assertions
Assert.That(MyArray, Has.Exactly(3).Items);
Assert.That(MyArray, Has.Length.EqualTo(3));
//Assert.That(MyArray, Has.Count.EqualTo(3)); // System.ArgumentException : Property Count was not found on System.Int32[]. (Parameter 'name')
Assert.That(MyCollection, Has.Exactly(3).Items);
Assert.That(MyCollection, Has.Count.EqualTo(3));
//Assert.That(MyCollection, Has.Length.EqualTo(3)); // System.ArgumentException : Property Length was not found on System.Collections.Generic.List`1[System.Int32]. (Parameter 'name')
Assert.That(MyEnumerable, Has.Exactly(3).Items);
//Assert.That(MyEnumerable, Has.Count.EqualTo(3)); // System.ArgumentException : Property Count was not found on System.Linq.Enumerable+RangeIterator. (Parameter 'name')
//Assert.That(MyEnumerable, Has.Length.EqualTo(3)); // System.ArgumentException : Property Length was not found on System.Linq.Enumerable+RangeIterator. (Parameter 'name')
// FluentAssertions
MyArray.Should().HaveCount(3);
MyCollection.Should().HaveCount(3);
MyEnumerable.Should().HaveCount(3);
}
Other examples of clunkiness when it comes to Intellisense:
Assert.That(MyArray, Has.None.Zero); // Pass
Assert.That(MyArray, Is.Not.Zero); // Pass - but probably means something entirely different
// Why do the following even compile?
//Assert.That(MyArray, Has.Exactly(3).Items.All.Exist); // Expected: IEnumerable But was: Int32 (Parameter 'actual')
//Assert.That(MyArray, Has.Exactly(3).Items.All.Not.EqualTo(0)); // Expected: IEnumerable But was: Int32 (Parameter 'actual')
//Assert.That(MyArray, Has.Exactly(3).Items.And.All.All.All.Not.EqualTo(0)); // Expected: IEnumerable But was: Int32 (Parameter 'actual')
Finally, I'm wondering whether it's possible to (1) match using a lambda expression, and (2) drill down into a match to assert its properties. Is there something equivalent in NUnit?
// FluentAssertions
MyArray.Should().ContainSingle(x => x > 2).Which.Should().Be(3);
MyArray.Should().ContainSingle(x => x > 2).Which.Should().Be(3).And.NotBe(4);
var colors = new[] { Color.Red };
colors.Should().ContainSingle(x => x.IsKnownColor).Which.R.Should().Be(255);
// NUnit expected syntax
//Assert.That(MyArray, Contains.Single(x => x > 2) (...) // Syntax error
//Assert.That(MyArray, Has.One.Match(x => x > 2) (...) // Syntax error
//Assert.That(colors, Has.Exactly(1).Items.With.R (...) // Syntax error
- 主要言語
- Dockerfile
- スター
- 601
- フォーク
- 160
- 平均マージ
- 22時間 18分
- マージ済み PR(30日)
- 6
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nunit/docs のほかの issue
-
area:adapter type:newpage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
Document why output from ASP.NET Core handlers (WebApplicationFactory) is not captured, and the workarounds対応中かも @SeanKilleen が 36 日前に担当しました。 オープンarea:framework type:update
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
-
type:newpage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
Dependency Dashboardオープン
難易度 3/5 1〜2日 初心者へのやさしさ 15/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
google/elephant-goldfish-model#586 ·
メンテナーはふだん 2 日以内に返信
-
documentation Entwickler
難易度 1/5 1時間未満 初心者へのやさしさ 89/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
memtomem/memtomem-stm#1657 ·
メンテナーはふだん 1 日以内に返信
-
Help with the docsオープンdocumentation good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
lightninglabs/layertree#28 ·