I was trying to run our existing tests which use NUnit and AwesomeAssertions with MTP. However, I got an error of the type
NUnit.Framework.AssertionException : Expected a <NUnit.Framework.AssertionException> to be thrown, but found <NUnit.Framework.AssertionException>:
NUnit.Framework.AssertionException: Expected string to be <null>, but found "foo".
at AwesomeAssertions.Execution.LateBoundTestFramework.Throw(String message)
[...]
The cause of this error is, that the exception we throw is from a different Assembly (the values of Exception.GetType().Assembly.m_assembly differ). We get it by scanning AppDomain.CurrentDomain.GetAssemblies(), which accesses the default AssemblyLoadContext.
The problem appears with NUnit3TestAdapter v 6.0.0-alpha.100, but not with 5.2.0.
And only, if the NUnit.Framework.FixtureLifeCycle is specified in the project itself.
I know, a lot of 'ifs', but I'm stuck looking for the cause, or what we could do on part of AwesomeAssertions to fix this.
Repro:
MyProject.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<EnableNUnitRunner>true</EnableNUnitRunner>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AwesomeAssertions" Version="9.2.1" />
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.0.0-alpha.100" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="NUnit.Framework.FixtureLifeCycle">
<_Parameter1>NUnit.Framework.LifeCycle.InstancePerTestCase</_Parameter1>
<_Parameter1_IsLiteral>true</_Parameter1_IsLiteral>
</AssemblyAttribute>
</ItemGroup>
</Project>
Test.cs:
using AwesomeAssertions;
using NUnit.Framework;
public sealed class ExceptionTests
{
[Test]
public void TestMethod_AwesomeAssertions()
{
Action act = () => "foo".Should().BeNull();
act.Should().Throw<AssertionException>();
}
}
Either commenting the AssemblyAttribute or changing the adapter version to 5.2.0 fixes the problem.
Any clue, which changes in the adapter may cause this?
I was trying to run our existing tests which use NUnit and AwesomeAssertions with MTP. However, I got an error of the type
The cause of this error is, that the exception we throw is from a different
Assembly(the values ofException.GetType().Assembly.m_assemblydiffer). We get it by scanningAppDomain.CurrentDomain.GetAssemblies(), which accesses the defaultAssemblyLoadContext.The problem appears with NUnit3TestAdapter v 6.0.0-alpha.100, but not with 5.2.0.
And only, if the
NUnit.Framework.FixtureLifeCycleis specified in the project itself.I know, a lot of 'ifs', but I'm stuck looking for the cause, or what we could do on part of AwesomeAssertions to fix this.
Repro:
MyProject.csproj:Test.cs:Either commenting the
AssemblyAttributeor changing the adapter version to 5.2.0 fixes the problem.Any clue, which changes in the adapter may cause this?