Skip to content
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

MSTest.Extensions 报空引用异常,待进一步调查 #24

Open
JasonGrass opened this issue Nov 6, 2024 · 2 comments
Open

MSTest.Extensions 报空引用异常,待进一步调查 #24

JasonGrass opened this issue Nov 6, 2024 · 2 comments

Comments

@JasonGrass
Copy link

JasonGrass commented Nov 6, 2024

使用的时候,发现如下错误,使用传统的 [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

@JasonGrass
Copy link
Author

最简复现 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);
        });
    }
}

CunitDemo.zip

@lindexi
Copy link
Member

lindexi commented Nov 7, 2024

@JasonGrass 这是更底层单元测试框架带过来的问题

核心问题是原本采用反射找调用堆栈的科技,这个科技会被框架层变更时炸了。现在 CUnit 采用的是比较古老的方式,也许需要摸索一下更新的方式了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants