sio / LibPQ

Detach your M code from workbooks to reuse it! Import modules from local or web storage (unlimited number of sources)
Apache License 2.0
76 stars 21 forks source link

Allow for Microsoft-Format unittests to be run by the unit testing framework #14

Closed metamoof closed 6 years ago

metamoof commented 6 years ago

Hi,

Microsoft have also release a unit testing framework for powerquery, though it requires the framework to be in the same file, by the looks of things.

It would be good if the unittest module could also cope with unit tests expressed as Facts, to make it easy for people who started in that framework to port it to the LibPQ way of doing things

sio commented 6 years ago

Thank you for pointing that out! It's great that they have finally offered an unit testing solution. It is unfortunate though that it is not included into the standard library. Copy-pasting functions into each project makes updating and maintaining them very difficult. I suspect the framework will be significantly reworked when (and if) it'll get widely adopted, and only then (maybe) it will become part of the language.

Even though I see no benefits to their approach, adding support for it was an interesting challenge :) I've added my own implementation of Facts and Facts.Summarize functions to the ms-tests branch. They are fully compatible input-wise with Microsoft's implementation but produce output that can be integrated into existing LibPQ UnitTest framework. More than that, UnitTest.Discover now supports test discovery for fact based tests if they are marked with proper metadata (LibPQ.TestSuite="Facts")!

The code will remain in the feature branch for a while, but please test it and report any problems. Sometime later I'll write the required documentation and will merge ms-tests into master.

PS: Execute LibPQ("UnitTest.Discover")(false) and Facts.Summarize(LibPQ("Tests.MicrosoftUnitTestDemo.pq")) to see new tests in action. Sample test code is included into Modules/Tests.MicrosoftUnitTestDemo.pq

sio commented 6 years ago

Support for fact based tests has been merged into master. See this article for documentation.

Thank you again!