CUnit
CUnit copied to clipboard
MSTest.Extensions 报空引用异常,待进一步调查
使用的时候,发现如下错误,使用传统的 [TestMethod] 没有问题。
还没有进一步调查,回头弄个最小 demo 复现。
矩阵水平镜像
源: ImagePixelDataHandleTest.cs 行 16
持续时间: 5 毫秒
消息:
执行测试时引发了异常。如果使用的是扩展 TestMethodAttribute,请与供应商联系。
错误消息: Object reference not set to an instance of an object.,
堆栈跟踪:
at MSTest.Extensions.Utils.ReflectionExtensions.GetField(Object source, String fieldName)
at MSTest.Extensions.Core.TestMethodProxy.ReflectionMemberInit()
at MSTest.Extensions.Core.TestMethodProxy..ctor(ITestMethod testMethod)
at MSTest.Extensions.Contracts.ContractTestCaseAttribute.CreateTestMethodProxy(ITestMethod testMethod)
at MSTest.Extensions.Contracts.ContractTestCaseAttribute.Execute(ITestMethod testMethod)
at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestMethodRunner.ExecuteTest(TestMethodInfo testMethodInfo) in /_/src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs:line 418
最简复现 demo
// csporj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest" Version="3.6.2" />
<PackageReference Include="MSTestEnhancer" Version="2.2.1" />
</ItemGroup>
</Project>
// Class1.cs
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MSTest.Extensions.Contracts;
namespace CunitDemo;
[TestClass]
public class Class1
{
[ContractTestCase]
public void TestMethod1()
{
"单元测试1".Test(() =>
{
var expect = 1;
var actual = 1;
Assert.AreEqual(expect, actual);
});
}
}
@JasonGrass 这是更底层单元测试框架带过来的问题
核心问题是原本采用反射找调用堆栈的科技,这个科技会被框架层变更时炸了。现在 CUnit 采用的是比较古老的方式,也许需要摸索一下更新的方式了
预计已经修复,先发布在各个项目试试