Nested AssertionScopes do not print inner scope reportables
See original GitHub issueDescription
Nested AssertionScopes only report the outer-most scope reportables on failure. This is true regardless of whether the outer scope has any reportables – i.e., if only the inner scope has reportables, nothing is reported.
Complete minimal example reproducing the issue
[TestMethod]
public void TestNestedAssertionScopes()
{
using (var outerScope = new AssertionScope())
{
outerScope.AddReportable("outerReportable", "foo"); // no behavior change if this is omitted
// in my real use case, the inner scope is in a for loop with changing innerScope reportable values, so I can't use a single scope;
// the outer scope is used to ensure that a failure of one loop item continues running the rest of the loop
using (var innerScope = new AssertionScope())
{
innerScope.AddReportable("innerReportable", "bar");
int testVal = 2;
testVal.Should().Be(1);
}
}
}
Expected behavior:
Message: Expected testVal to be 1, but found 2.
With outerReportable:
foo
With innerReportable:
bar
Actual behavior:
Message: Expected testVal to be 1, but found 2.
With outerReportable:
foo
Versions
- Which version of Fluent Assertions are you using? 6.5.1
- Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.1. .NET Framework 4.7.2
Additional Information
using Microsoft.VisualStudio.TestTools.UnitTesting test framework
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Releases - Fluent Assertions
Properties() , now also includes static properties - #2054; Nested AssertionScopes now print the inner scope reportables - #2044; Throw ArgumentException ...
Read more >Using Assertion Scopes to execute multiple Assertions in ...
Using Assertion Scopes, we can batch multiple assertions into a AssertionScope so that FluentAssertions will only throw the one exception at ...
Read more >about nested transaction, the outer scope gives me ...
I have nested transactions. The outer method calls an inner method SaveChangesToSource that opens another transaction scope. Actually I know my ...
Read more >Coding Rules
An inner class is a nested class that is not explicitly or implicitly declared static. Inner classes may not declare static initializers (§8.7)...
Read more >American Carbon Registry® Nested REDD+ Standard
5 Defined scope of REDD+ activities: The jurisdictional framework shall include the project activity type to be registered on ACR as an eligible...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Me and my friend Ruijin92 are two new Contributors working together on Issues and having our first experience in an open source project. We already have a solution for this bug and would be happy if you assign this “good first issue” to me or Ruijin92.
I think that’s an acceptable solution. We just need to make sure that
Discard
also discard the reportables.