How to generate sequence diagrams automatically on executing junit

点点圈 提交于 2021-02-07 19:53:36

问题


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.

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.


回答1:


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.

Direct approach

  • Set up your logging to log using json, it makes the rest much simpler: https://www.baeldung.com/java-log-json-output

  • 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.

  • 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 :-)

  • Filter the log entries so you get only the ones you are interested in. Using the "jq" utility is a decent choice.

  • Process the filtered output to generate "plant uml" input files (http://plantuml.com/) for sequence diagrams.

  • Process the plant UML files to get sequence diagrams.

  • Done.

Industrial approach

  • 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.



来源:https://stackoverflow.com/questions/29714440/how-to-generate-sequence-diagrams-automatically-on-executing-junit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!