Assert.That on a null non-generic IEnumerable throws ArgumentNullException, so IsNull() cannot pass
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start at the Assert.That overload for non-generic IEnumerable and compare its null handling with the generic IEnumerable<T> and object overloads. Check the related IsNull() and other assertion paths; add coverage for null and non-null values. Done when IsNull() passes for null IEnumerable and other assertions report assertion failures instead of ArgumentNullException.
Written by the indexing model from the issue text.
Description
Assert.That(x).IsNull() throws ArgumentNullException when x is a null non-generic IEnumerable, so the assertion can never pass. With TUnit 1.79.0:
IEnumerable? renderings = null;
await Assert.That(renderings).IsNull(); // ArgumentNullException: Value cannot be null. (Parameter 'source')
The generic and object overloads accept the same null value:
IEnumerable<int>? items = null;
await Assert.That(items).IsNull(); // passes
object? value = null;
await Assert.That(value).IsNull(); // passes
The overload taking a non-generic IEnumerable also declares its parameter non-nullable, so the compiler warns (CS8604) at the call above. Casting the value to object? makes the assertion pass.
Expected: IsNull() passes for a null non-generic IEnumerable, as it does for IEnumerable<T>. Other assertions on a null value should fail with an assertion failure rather than ArgumentNullException.
Found while migrating an xUnit suite, where Assert.Null(renderings) on a non-generic IEnumerable passed.
- Dominant language
- C#
- Stars
- 4k
- Forks
- 139
- Avg merge
- 7h 16m
- Merged PRs (30d)
- 355
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from thomhurst/TUnit
-
bug P3
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
thomhurst/TUnit#7585 · 2 comments ·
Maintainers usually reply within 1 day
-
Mock and core generator test restores report vulnerable System.Security.Cryptography.Pkcs versionsOpendependencies P2
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
thomhurst/TUnit#7412 · 8 comments ·
Maintainers usually reply within 1 day
-
enhancement P3 performance
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
thomhurst/TUnit#7380 · 2 comments ·
Maintainers usually reply within 1 day
-
bug github_actions P2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
thomhurst/TUnit#7229 · 1 comment ·
Maintainers usually reply within 1 day
-
benchmarks enhancement P3 performance
Difficulty 3/5 1-2 days Newbie friendliness 48/100
thomhurst/TUnit#7683 · 2 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sebastienros/jint#4531 ·
Maintainers usually reply within 1 day
-
Unable to buildOpenBug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
area/automation area/sdk kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
unoplatform/uno.templates#2406 ·
Maintainers usually reply within 1 day
-
bug frontend ui
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
agentic-workflows
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day