我的 Verify.Bunit 测试为什么失败,并且没有生成接收到的文件?

huangapple go评论66阅读模式
英文:

Why is my Verify.Bunit test failing and not producing a received file?

问题

I am using the Verify.Xunit and Verify.Bunit packages in my test project but they have started failing and I can't figure out why.

我正在使用 Verify.XunitVerify.Bunit 包在我的测试项目中,但它们开始失败,我无法弄清楚原因。

Example simple test - just renders a component:

示例简单测试 - 仅渲染一个组件:

[Fact]
public Task TestInputBaseRendering_Default()
{
  //Arrange: render the base markup
  var cut = this.Render(TestInputBaseRendering_Default_Markup);

  // Act: 

  // Assert: 
  return Verify(cut);
}

The first time I run the test, it produces a received file and an empty verified file and launches my diff tool where I can copy the received text into the verified file and save - this is expected normal behavior.

第一次运行测试时,它会生成一个 received 文件和一个空的 verified 文件,然后启动我的差异工具,我可以将 received 文本复制到 verified 文件中并保存 - 这是预期的正常行为。

Sample output now saved as TestInputBaseRendering_Default.verified.html:

现在将示例输出保存为 TestInputBaseRendering_Default.verified.html

<input type="text" autocomplete="off" name="" id="id1" blazor:onchange="1" blazor:elementreference="Guid_1">

When I then re-run the test it should produce the same output (debugging and inspecting the object being passed to Verify(cut) shows the correct output) - save it in TestInputBaseRendering_Default.received.html and compare this to TestInputBaseRendering_Default.verified.html

然后,当我重新运行测试时,它应该产生相同的输出(调试和检查传递给 Verify(cut) 的对象显示正确的输出) - 将其保存在 TestInputBaseRendering_Default.received.html 中,并与 TestInputBaseRendering_Default.verified.html 进行比较。

If there was a difference, it should launch my diff tool to inspect the variance in output.

如果有差异,它应该启动我的差异工具以检查输出的差异。

What is actually happening is the test fails again does not open the diff tool and does not save a received file:

实际发生的情况是测试再次失败,不会打开差异工具,也不会保存 received 文件:

Test result:

测试结果:

Message: 
VerifyException : Directory: C:\Users\xxxxx\source\repos\xxxxx\tests\xxxxx.test\Inputs\SBInputBaseTests
Delete:
  - InputBaseRenderingTests.TestInputBaseRendering_Label.verified.html.bak
  - InputBaseRenderingTests.TestInputBaseRendering_Label.verified.txt.bak
Equal:
  - Received: InputBaseRenderingTests.TestInputBaseRendering_Label.received.txt
    Verified: InputBaseRenderingTests.TestInputBaseRendering_Label.verified.txt
  - Received: InputBaseRenderingTests.TestInputBaseRendering_Label.received.html
    Verified: InputBaseRenderingTests.TestInputBaseRendering_Label.verified.html

I have no idea how to resolve that the test now fails every time and does not save the received file.

我不知道如何解决测试现在每次都失败且不保存 received 文件的问题。

I have checked by debugging the test that the component is rendered correctly each time - the problem lies somewhere in the Verify system, for which I cannot find any additional logging or debugging help.

我已经通过调试测试来检查,每次组件都正确渲染 - 问题出现在 Verify 系统的某个地方,但我找不到任何额外的日志记录或调试帮助。

英文:

I am using the Verify.Xunit and Verify.Bunit packages in my test project but they have started failing and I can't figure out why.

Example simple test - just renders a component:

[Fact]
public Task TestInputBaseRendering_Default()
{
  //Arrange: render the base markup
  var cut = this.Render(TestInputBaseRendering_Default_Markup);

  // Act: 

  // Assert: 
  return Verify(cut);
}

The first time I run the test, it produces a received file and an empty verified file and launches my diff tool where I can copy the received text into the verified file and save - this is expected normal behaviour.

Sample output now saved as TestInputBaseRendering_Default.verified.html:

<input type="text" autocomplete="off" name="" id="id1" blazor:onchange="1" blazor:elementreference="Guid_1">

When I then re-run the test it should produce the same output (debugging and inspecting the object being passed to Verify(cut) shows the correct output) - save it in TestInputBaseRendering_Default.received.html and compare this to TestInputBaseRendering_Default.verified.html

If there was a difference, it should launch my diff tool to inspect the variance in output.

What is actually happening is the test fails again does not open the diff tool and does not save a received file:

Test result:

Message: 
VerifyException : Directory: C:\Users\xxxxx\source\repos\xxxxx\tests\xxxxx.test\Inputs\SBInputBaseTests
Delete:
  - InputBaseRenderingTests.TestInputBaseRendering_Label.verified.html.bak
  - InputBaseRenderingTests.TestInputBaseRendering_Label.verified.txt.bak
Equal:
  - Received: InputBaseRenderingTests.TestInputBaseRendering_Label.received.txt
    Verified: InputBaseRenderingTests.TestInputBaseRendering_Label.verified.txt
  - Received: InputBaseRenderingTests.TestInputBaseRendering_Label.received.html
    Verified: InputBaseRenderingTests.TestInputBaseRendering_Label.verified.html

I have no idea how to resolve that the test now fails every time and does not save the received file.

I have checked by debugging the test that the component is rendered correctly each time - the problem lies somewhere in the Verify system, for which I cannot find any additional logging or debugging help.

答案1

得分: 1

它没有启动差异工具,因为输入与验证过的文件匹配。

它告诉您有 2 个意外的文件应该被删除

  • InputBaseRenderingTests.TestInputBaseRendering_Label.verified.html.bak
  • InputBaseRenderingTests.TestInputBaseRendering_Label.verified.txt.bak

如果您使用 diffenginetray (https://github.com/VerifyTests/DiffEngine/blob/main/docs/tray.md),它会自动执行这个。或者您可以使用其他方法来管理快照

https://github.com/VerifyTests/Verify#snapshot-management

关于 WinMerge

> 确保文件备份要么被 禁用,要么被更改为使用 全局备份文件夹

英文:

it isnt launching a diff tool since the inputs match the verified files.

it is telling you that there are 2 unexpected files that should be deleted

  • InputBaseRenderingTests.TestInputBaseRendering_Label.verified.html.bak
  • InputBaseRenderingTests.TestInputBaseRendering_Label.verified.txt.bak

if u use diffenginetray (https://github.com/VerifyTests/DiffEngine/blob/main/docs/tray.md) it will automate this. or u can use one of the other approaches to managing snapshots

https://github.com/VerifyTests/Verify#snapshot-management

re winmerge

> Ensure that file backups are either disabled or changed to use a Global backup folder

huangapple
  • 本文由 发表于 2023年6月4日 23:52:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76401229.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定