Gallio DynamicTestFactory 和断言

发布于 2024-12-02 08:50:51 字数 1318 浏览 0 评论 0原文

我正在尝试使用 MbUnit 中的 DynamicTestFactory 来动态生成测试套件和测试用例。我还有自己的 TestLauncher 来从控制台启动我的测试。

一切看起来都不错,但我在做任何断言时都遇到问题。例如,如果我在检查变量是否为 null 时尝试执行 Assert.Fail,则我的控制台程序会立即中断,并显示如下内容:

   at Gallio.Framework.Assertions.AssertionContext.Scope.ThrowFailureAccordingToBehavior(AssertionFailure failure)
   at Gallio.Framework.Assertions.AssertionContext.Scope.SubmitFailure(AssertionFailure failure, Boolean noThrow)
   at Gallio.Framework.Assertions.AssertionContext.Scope.SubmitFailure(AssertionFailure failure)
   at Gallio.Framework.Assertions.AssertionContext.SubmitFailure(AssertionFailure failure)
   at Gallio.Framework.Assertions.AssertionHelper.Fail(AssertionFailure failure)
   at MbUnit.Framework.Assert.Fail(String messageFormat, Object[] messageArgs)
   at Dundas.Dashboard.TestSystem.TestPrograms.DashboardImageCompare.<>c__DisplayClass6.<CreateTestSuiteByDataStore>b__1() in C:\...\test.cs:line 115
   at MbUnit.Framework.TestCase.OnExecuteSelf()
   at MbUnit.Framework.TestDefinition.<>c__DisplayClass9.<RunDynamicTest>b__8()
   at Gallio.Common.Concurrency.ThreadAbortScope.Run(Action action)
   at Gallio.Framework.Sandbox.Run(MarkupDocumentWriter markupDocumentWriter, Action action, String description)

Gallio 不应该为我捕获与断言相关的所有异常吗?我应该如何解决这个问题?

I am trying to use DynamicTestFactory in MbUnit to generate test suites and test cases on the fly. I also have my own TestLauncher to launch my test from console.

Everything seems good but I am having a problem doing any kind of assertion. For example, if I try to do Assert.Fail when I check that a variable is null, my console program breaks at that point immediately with something like the following:

   at Gallio.Framework.Assertions.AssertionContext.Scope.ThrowFailureAccordingToBehavior(AssertionFailure failure)
   at Gallio.Framework.Assertions.AssertionContext.Scope.SubmitFailure(AssertionFailure failure, Boolean noThrow)
   at Gallio.Framework.Assertions.AssertionContext.Scope.SubmitFailure(AssertionFailure failure)
   at Gallio.Framework.Assertions.AssertionContext.SubmitFailure(AssertionFailure failure)
   at Gallio.Framework.Assertions.AssertionHelper.Fail(AssertionFailure failure)
   at MbUnit.Framework.Assert.Fail(String messageFormat, Object[] messageArgs)
   at Dundas.Dashboard.TestSystem.TestPrograms.DashboardImageCompare.<>c__DisplayClass6.<CreateTestSuiteByDataStore>b__1() in C:\...\test.cs:line 115
   at MbUnit.Framework.TestCase.OnExecuteSelf()
   at MbUnit.Framework.TestDefinition.<>c__DisplayClass9.<RunDynamicTest>b__8()
   at Gallio.Common.Concurrency.ThreadAbortScope.Run(Action action)
   at Gallio.Framework.Sandbox.Run(MarkupDocumentWriter markupDocumentWriter, Action action, String description)

Shouldn't Gallio capture all the exceptions which are related to assertions for me? How should I go around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筱果果 2024-12-09 08:50:51

我当时就傻了。这只是因为我正在调试模式下运行。如果我切换到发布(或使用反射调用该方法),它不会像以前那样在断言失败时中断。

I was being dumb. It's just because I am running in debug mode. If I switch to release (or invoke the method using reflection), it won't break at failed assertion like before.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文