如何编写MassTransitStateMachine单元测试? [英] How to write MassTransitStateMachine unit tests?

查看:120
本文介绍了如何编写MassTransitStateMachine单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于开始在MassTransit中利用出色的Automatonymous组件,并且我想通过新的状态机TDD.

在此处阅读MT文档后( http://masstransit-project .com/MassTransit/advanced/sagas/automatonymous.html )并花了一些时间在Google搜索上,我发现MT/Automatonymous Git存储库中的单元测试看起来像这样:

特别地,_machine.RaiseEvent(....)方法似乎正是我能够通过测试提供的刺激来驱动状态机所需要的.

接下来,我去寻找这种超载...原来,这是一个扩展方法,似乎住在这里:

https://github.com/MassTransit/Automatonymous /blob/15e9181ed05e37ff71e85b514aafc351b1edf27f/src/Automatonymous/RaiseEventExtensions.tt

那是我被困住的地方.我不确定使用这些扩展方法进行测试的正确方法是什么? * .tt是文本生成模板格式...是否将它们作为nuget软件包的一部分安装?如何获得对扩展程序的访问权限?和/或更广泛地说,为从MassTransitStateMachine<T>继承的状态机编写单元测试的推荐方法是什么?

此处的后续问题:如何成功驾驶通过InMemoryTestHarness进行MassTransitStateMachine吗?

解决方案

您引用的测试不是来自MassTransit,而是来自Automatonymous库,该库不属于MassTransit.

您正在寻找的东西可能在这里找到

  • 状态机传奇测试,使用该测试框架.问题在于测试框架已与NUnit耦合
  • 经典" saga测试使用测试工具.测试工具与框架无关,但是至少在主仓库中没有将状态机和测试工具结合在一起的测试.
  • 状态机传奇测试在主仓库外使用测试硬度.这是我的项目,我使用xUnit,因为我正在使用测试工具,所以很好.但是,您可以看到跳过了一个测试,并且我不记得确切的问题是什么,但是有一些我无法解决的问题.这可能与我测试的持久性有关.

I'm finally starting to leverage the excellent Automatonymous components within MassTransit, and I'd like to TDD my way through my new state machines.

After reading over the MT docs here (http://masstransit-project.com/MassTransit/advanced/sagas/automatonymous.html) and spending some time Googling, I found unit tests right in the MT/Automatonymous Git repo that looked like the way to go:

In particular, the _machine.RaiseEvent(....) method seemed to be exactly what I needed to be able to drive the state machine with test-provided stimuli.

Next, I went hunting for that overload... Turns out it's an extension method that appears to live here:

https://github.com/MassTransit/Automatonymous/blob/15e9181ed05e37ff71e85b514aafc351b1edf27f/src/Automatonymous/RaiseEventExtensions.tt

That's where I've gotten stuck. I'm not sure what the right way is to make use of these extension methods for testing? *.tt is a text generation template format... Are these installed as part of the nuget package? How do I gain access to the extensions? and/or more broadly, what is the recommended way to write unit tests for state machines inheriting from MassTransitStateMachine<T>?

Follow-up question here: How to successfully drive a MassTransitStateMachine via the InMemoryTestHarness?

解决方案

The test you reference are not from MassTransit but from the Automatonymous library, which is not part of MassTransit.

What you are looking for can be probably found here:

  • State machine saga tests using the test framework. The issue is that the test framework is coupled to NUnit
  • "Classic" saga tests using the test harness. The test harness is framework-agnostic but there are no tests that combine state machines and test harness, at least in the main repo.
  • State machine saga tests using the test hardness, outside of the main repo. This is my project and I use xUnit, since I am using the test harness, it is fine. However, you can see that one test is skipped and I don't remember exactly what was the issue but there was something there I couldn't resolve. This might be related to the persistence that I test though.

这篇关于如何编写MassTransitStateMachine单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆