Gallio DynamicTestFactory和断言

时间:2011-08-29 19:21:33

标签: unit-testing mbunit gallio

我正在尝试在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不应该捕获与断言相关的所有异常吗?我该如何解决这个问题呢?

1 个答案:

答案 0 :(得分:1)

我是愚蠢的。这只是因为我在调试模式下运行。如果我切换到释放(或使用反射调用方法),它将不会像以前那样在失败的断言中中断。