Unit testing Modelica component library?
Asked Answered
D

4

7

I'm creating a library of components in Modelica, and would appreciate some input on techniques for unit testing the package.

So far I have a test package, consisting of a set of models, one per component. Each test model instantiates a component, and connects it to some very simple helper classes that provide the necessary inputs and outputs.

This works fine when using it interactively in the OMEditor, but I'm looking for a more automated solution with pass/fail criteria etc.

Should I start writing .mos scripts, or is there another/better way ?

Thanks.

Dispart answered 22/3, 2016 at 14:31 Comment(2)
I wonder if the way in which jModelica checks its versions represents a good way of performing the Unit Testing... but how do they do this...? Perhaps via python script and checking FMUs?Solnit
Here is a nice presentation that was given by Dassault at the Modelica 2017 conference: modelica.org/events/modelica2017/documents/…Woke
H
7

I like how Openmodelica testing results look, see

No idea how they are doing it, though. Obviously some kind of regression testing is done, with previous results stored, but no idea if that is from some testing library or self-made.


In general, I find it kinda sad/suboptimal, that there isn't "the one" testing solution everybody can/should use (cf. e.g. nose or pytest in the python ecosystem), instead everybody seems to cook up their own solutions (or tries to), and all you find is some Modelica conference papers (often without a trace of implementation) or unmaintained library of unknown status.

Off the top of my head, I found/know of (some already linked in other answers here)

This seems like a pathological instance of https://xkcd.com/927/. It's kinda impossible for a (non-dev) user to know which of those to choose, which are actually good/usable/available/...

(Not real testing, but also relevant: parsing and semantic analysis using ANTLR: modelica.org/events/Conference2003/papers/h31_parser_Tiller.‌​pdf)

Hydrostat answered 24/3, 2016 at 12:31 Comment(11)
I've made an in house unit testing platform for our libraries. It looks quite like the openModelica hudson. I used a text template to generate modelica script and parse test results to a JUNIT xml format. In Dymola, you can run .mos scripts directly from batch or direct API calls from python scripts and javascripts. If you are interested in further details shoot me an email, I believe some further discussions will make my stuff a better platform.Eunuchize
Very detailed list - thanks ! I agree that it's a shame there isn't a common solution (or class of solutions) that address this. I do a lot of work in the .Net/C# world, where there are many testing solutions that all follow the same pattern: xunit, nunit etc etc, each with a VS integrated test runner AND automated build support. There are so many things to like about Modelica, but the lack of good devops tooling stands out as a big minus to me.Dispart
Another example of unit testing and overall project implementation for Modelica that seems to have been done well is the Buildings Library from Lawrence Berkeley National lab. It'd probably good to add it to the list.Solnit
I added some more details about the different packages that I dug up. So far it's looking bleak. :-/Hydrostat
There is yet another effort to get test and verification standardised: Modelica_Requirements ep.liu.se/ecp/118/067/ecp15118625.pdfHemispheroid
Dietmar, do you know where the library is available from? This looks good, but the paper happily talks about "open source" and "implemented" and "can be used", but does not offer a URL, and searching via Google and Impact I came up empty.. :-/Hydrostat
Not real testing, but also relevant here: parsing and semantic analysis using ANTLR: modelica.org/events/Conference2003/papers/h31_parser_Tiller.pdfWoke
BuildingsPy should now work with Python 3, see github.com/lbl-srg/BuildingsPy/issues/94Woke
@Hydrostat You already know all this, but you might still like this presentation: docs.google.com/presentation/d/…Woke
nice compilation of the current state by mthorade. Seems to be for the 2017 conference, hopefully can get an actually downloadable version from there later. Also, maybe it gets something moving w.r.t. a standard solution..Hydrostat
A detailed summary of the available testing solutions can also be found in modelica.org/events/modelica2017/documents/…. Brief guides for installation and how to setup tests are included for the tool which are freely available.Vogue
H
3

Writing a .mos script would be one way but there is also a small proof-of-concept library by Michael Tiller: XogenyTest which you could use as a basis.

Hemispheroid answered 23/3, 2016 at 6:56 Comment(4)
Thanks - anything by Michael Tiller is worth looking at.Dispart
yeah, but the fact that this library only has very few commits and hasn't been updated in 3 years makes me think it didn't really work out well (otherwise people would have adopted it). :-/Hydrostat
Christoph, it was simply done as a proof of concept and probably not meant to be a full project. Still it can serve as useful.Hemispheroid
Yes, I gathered that, but the question that occurs to me: if it could indeed serve as useful, why was it not developed further/maintained/developed into a full package? In any case, it's on my list of things to evaluate some time...Hydrostat
E
3

I prefer using the .mos script, it works pretty well when you further integrate your test framework into a continuous integration tool. BuildingPy is a good example of this, though it's not implemented in CI tools, it's still a good tool.

Here's a reference of a good framework design: UnitTesting: A Library for Modelica Unit Testing

Eunuchize answered 23/3, 2016 at 12:15 Comment(1)
Thanks for the link - I'll have a browse.Dispart
E
3

If you have Mathematica and SystemModeler you can run the simulation from Mathematica and use the VerificationTest "function" to test: VerificationTest[Abs[WSMSimulate["HelloWorld"]["x", .1] - .90] < .01].

Multiple tests can then be simulated in a TestReport[].

Educated answered 23/3, 2016 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.