-
Notifications
You must be signed in to change notification settings - Fork 733
Add support for xUnit.net v3 #2718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Qodana for .NETIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
Pull Request Test Coverage Report for Build 11978451397Details
💛 - Coveralls |
Oops, Qodana Scan is failing because of a license error. 🙁
|
Yes, and I already have a nice license, but somehow it's not working yet. Working with JetBrains to resolve this ASAP. |
// For netfx the assembly is not in AppDomain by default, so we can't just scan AppDomain.CurrentDomain | ||
assembly = Assembly.Load(new AssemblyName("xunit.assert")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We added this in #384 to correctly throw XUnitException
despite xunit.assert.dll
not yet being loaded into the App Domain for netfx.
The reason this PR works is due to how https://github.com/fluentassertions/fluentassertions/pull/2712/files#diff-69d48f2874ce90a847fb038d9eb42b104dba380c129f7babfde78e9a3d73e65aL16-L17 changed the test.
By explicitly referencing XunitException
, we now trigger loading the xunit.assert
dll.
We should revert those simplifications.
At least for xunit as that's the only framework that is spread across multiple dll's, but I'd say we do it for all test frameworks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should revert those simplifications.
Indeed, I figured out why XunitException
was not referenced while working on this pull request. I'll revert #2712 as part of this pull request and add a comment why act.Should().Throw<XunitException>();
should not be used.
1aedaa7
to
62e78f3
Compare
catch (FileNotFoundException) | ||
{ | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add explicit tests that challenge these two catch
es? This one and the catch
below...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When_xunit3_is_used_it_should_throw_xunit_exceptions_for_assertion_failures
covers this catch (FileNotFoundException)
since it tries to load xunit.assert
first and fails. But adding a None.Specs
that references none of the supported testing frameworks and asserting that the fallback AssertionFailedException
is thrown is probably a good idea anyway.
For the second catch
(around expression.Compile()
) it's going to be very hard to test. I added it as a safety thinking that maybe Compile()
might fail on some platforms and falling back on Activator.CreateInstance
which was the original implementation. But maybe this whole expression thing is over-engineering since we're throwing an exception anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding a
None.Specs
that references none of the supported testing frameworks
That was a stupid idea! How are the tests going to be run without any testing framework? 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When_xunit3_is_used_it_should_throw_xunit_exceptions_for_assertion_failures covers this catch (FileNotFoundException) since it tries to load xunit.assert first and fails.
Coveralls mentioned this as "no coverage": see https://coveralls.io/builds/69359638/source?filename=Src%2FFluentAssertions%2FExecution%2FLateBoundTestFramework.cs#L45-47
That was a stupid idea! How are the tests going to be run without any testing framework?
Using an unsupported test framework like NSpec3 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coveralls mentioned this as "no coverage"
That's weird, I ran coverage in Rider and it was displayed as covered. Does Coveralls merge all different test runs? Also, I can't see anything in the link you posted, it says Source Not Available and doesn't display anything beside the file path: /Src/FluentAssertions/Execution/LateBoundTestFramework.cs
.

Using an unsupported test framework like NSpec3 🤔
I just tried with Fuchu but it did not end well. 🙁
Test run for ~/fluentassertions/Tests/TestFrameworks/Fuchu.Specs/bin/Debug/net472/Fuchu.Specs.exe (.NETFramework,Version=v4.7.2)
Microsoft (R) Test Execution Command Line Tool Version 17.10.0 (x64)
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
The active test run was aborted. Reason: Test host process crashed : =================================================================
External Debugger Dump:
=================================================================
Test Run Aborted.
Test run for ~/fluentassertions/Tests/TestFrameworks/Fuchu.Specs/bin/Debug/net6.0/Fuchu.Specs.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.10.0 (x64)
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
No test is available in ~/fluentassertions/Tests/TestFrameworks/Fuchu.Specs/bin/Debug/net6.0/Fuchu.Specs.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Additionally, path to test adapters can be specified using /TestAdapterPath command. Example /TestAdapterPath:<pathToCustomAdapters>.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it says Source Not Available
You have to sign-in first (e.g. using Github OAuth)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Coveralls merge all different test runs?
I think so. If you run build.(sh|ps1)
you run this like in the pipeline. When finished, you get a reports
directory beneath TestResults
. And there you can run the index.html
and browse the coverage files
Something went wrong with the coverage, since a lot of unrelated files are mentioned... |
We're out of luck today!
And indeed, the Coveralls status page acknowledges 500 errors. 🙁
But I found a solution to make 100% sure that the I'll force-push once the Coveralls outage is over to trigger a new build and see what's going on with the coverage. |
074483e
to
dbc451f
Compare
afe1754
to
fc2d540
Compare
Not sure what's happening with the coverage. Build 10700844516 says that AssemblyAssertions line 216 was uncovered. But looking at the base build, AssemblyAssertions line 216 is NOT covered! |
565ec55
to
bf96c6e
Compare
Time to rebase on |
I juste rebased on I also changed the status of this pull request from draft to ready for review. |
We know about the Qodana issue and are working with JetBrains to fix it. |
This reverts commit feb3147 and add a comment explaining why the exception types must not be referenced explicitly.
It's not relevant actually
Qodana for .NETIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Why did this class have to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new implementations covers all case without duplicating code.
- Try first if the exception assembly is already loaded into the AppDomain (all test frameworks) ⇒ available
- The exception assembly is not loaded and we don't try to load it (
mspec
,nunit
andmstestv2
) ⇒ not available - The exception assembly is not loaded and we try to load it (
tunit
,xunit2
andxunit3
) ⇒ available if it can be loaded
Since FluentAssertions don't take hard dependencies on test frameworks it can't know if an assembly is already loaded. So verifying first if the assembly is already loaded avoids going through the try/catch approach (which was done in the LoadableTestFramework
implementation) in case the assembly is already loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔Why do we need two new projects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XUnit3Core.Specs
project ensures that the catch (FileNotFoundException)
branch is covered in the FindExceptionAssembly
method. XUnit3Core.Specs
takes a dependency on xunit.v3.core
instead of xunit.v3
. And the difference between xunit.v3
and xunit.v3.core
is that the former has a dependency on xunit.v3.assert
(the exception assembly) and the later does not.
That's why I tried to explain in #2718 (comment)
@0xced the ball is yours for a while now ;-) |
I tried to address everything, let me know if something needs more clarification. |
@jnyrup do you feel the need to do an explicit review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't looked deeply into LateBoundTestFramework (on mobile right now) but everything looks good.
If there is something it can wait...
Awesome work @0xced |
(cherry picked from commit 3e00296)
(cherry picked from commit 3e00296)
(cherry picked from commit 3e00296)
(cherry picked from commit 3e00296)
Fixes #2709
Notes
The XUnit3Core.Specs project ensures that the catch (FileNotFoundException) branch is covered in the FindExceptionAssembly method. XUnit3Core.Specs takes a dependency on xunit.v3.core instead of xunit.v3. And the difference between xunit.v3 and xunit.v3.core is that the former has a dependency on xunit.v3.assert (the exception assembly) and the later does not.
The new
LateBoundTestFramework
covers all case without duplicating code.Since FluentAssertions don't take hard dependencies on test frameworks it can't know if an assembly is already loaded. So verifying first if the assembly is already loaded avoids going through the try/catch approach (which was done in the LoadableTestFramework implementation) in case the assembly is already loaded.
IMPORTANT
./build.sh --target spellcheck
or.\build.ps1 --target spellcheck
before pushing and check the good outcome