如何在执行junit时自动生成序列图 [英] How to generate sequence diagrams automatically on executing junit
问题描述
在eclipse中,我承担了在执行junit/test case时自动生成序列图"的任务.我正在学习UML.我发现了可以生成序列的工具,并且我知道junit,但是我如何将两者结合起来.
I have been given a task of "generate sequence diagrams automatically on execution of junit/test case" in eclipse. I am learning UML. I found tools that can generate a sequence, and I am aware of junit, but how do I club this both.
我发现很好的工具是UMLet,ModelGoon UML,对象辅助.但是我对ModelGoon归零了.我发现它简单易用.如何自动执行此任务,如果可以,请指导我.
The tools that I found good were UMLet,ModelGoon UML, Object Aid. But I zeroed in on ModelGoon. I found that simple and easy to use. How do I automate this task, if so please guide me.
如果还有其他可用的工具,请指导我.
If there are any-other tools that are available then guide me.
推荐答案
首先:这是一个非常好的主意,有几种解决方法.我将假设您使用的是jvm语言(例如Kotlin或Java),因此我将提出的建议对此有偏见.
First: This is a very good idea, and there are several ways to go about it. I will make the assumption that you are working in a jvm language (e.g. Kotlin or Java) so the suggestions I will make are biased by that.
-
设置您的日志记录以使用json进行日志记录,从而使其余的工作变得更加简单:建立一个库,在其中记录您所在组件/方法的名称以及正在处理的会话.有许多方式,但是一个简单的方法是线程局部变量:设置该变量以包含要跟踪的事物的名称("usecase foobar")和一些唯一的ID. (UUID是不错的选择).另一个方法是生成一些跟踪ID(或从外部交互中获取一个),并将其作为参数发送给所有涉及的方法.这两种方法都可以使用,实际上哪一种最简单取决于应用程序的体系结构.
Make a library where you log the name of the component/method you are in, and the session you are processing. There are many ways of doing this, but a simple one is to a thread local variable: Set the variable to contain the name of the thing you are tracing ("usecase foobar"), and some unique ID (UUIDs are a decent choice). Another would be to generate some tracing ID (or get one from an external interaction), and send that as a parameter to all involved methods. Both of these will work, and which one is the simplest in practice depends on the architecture of your application.
在要跟踪的方法中,编写一个日志条目,其中包含该跟踪信息(用例名称,跟踪ID或其任意组合),写入日志条目的位置以及任何其他信息您想添加到序列图中.
In the methods you want to trace, write a log entry that contains that tracing information (name of usecase, trace ID, or any combination thereof), the location where the log entry was written, and any other information you want to add to your sequence diagram.
正常运行测试.将产生一个日志.您需要能够检索该日志.可以使用多种方法来完成此操作,请使用一种:-)
Run your test normally. A log will be produced. You need to be able to retrieve that log. There are many ways this can be done, use one :-)
过滤日志条目,以便仅获取您感兴趣的日志条目.使用"jq"实用程序是一个不错的选择.
Filter the log entries so you get only the ones you are interested in. Using the "jq" utility is a decent choice.
处理过滤后的输出以生成植物uml"输入文件( http://plantuml.com/)用于顺序图.
Process the filtered output to generate "plant uml" input files (http://plantuml.com/) for sequence diagrams.
处理工厂UML文件以获得序列图.
Process the plant UML files to get sequence diagrams.
完成.
-
使用一些标准工具进行跟踪,例如" https://opentracing.io/"您可以使用此工具来开发您的应用程序,并使用该标准工具来提取图表.
Use some standard tooling for tracing like "https://opentracing.io/", instrument your application using this tooling, and extract your diagrams using that standard tooling.
这也将在生产中起作用,并且缩放可能比直接方法更好,但是如果缩放不是您的事,那么直接方法可能就是您想要做的.
This will also work in production an will probably scale much better than the direct approach, but if scaling isn't your thing, then the direct approach may be what you want to do.
这篇关于如何在执行junit时自动生成序列图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-