Is there a way to run unit tests in a given project which _does not_ require that test classes be exported first?
Hello,
It is time for me to eat my own dog's food and start implementing unit test running with coverage :) I will be inundating IRC with questions at this point, but I have a more general question first.
In this tutorial, it is supposed that your unit tests are exported as XML first... But that's not very practical. Is there a way, instead, to run all tests from a given project without having this export?
My first thought on how to do this would be to:
- grab the project (by name, I suppose?),
- grab the list of classes defined by this project,
- inspect the classes,
- consider unit tests only these classes which extend (directly or not) %UnitTest.TestCase,
- consider test methods only those methods whose name start with Test,
- run each method individually.
I'd have expected %UnitTest.Manager to provide such a method instead but it appears that it doesn't :/ At least, as far as I can see. And I still don't "see" much...
Do you have a better approach?
Regards
See the discussion in this previous post:
https://community.intersystems.com/post/unittest
Basically, you can use the /noload and /nodelete qualifiers, specifying the tests by class name. Be aware that if you forget the /nodelete qualifier, you'll delete your test classes.
Here's some code from the application I'm working on that might help. The "load/delete the test classes" behavior was annoying enough that we decided to always have the classes loaded on development/testing systems.
First, I think it's useful to have a Run() method in each unit test class, or in a subclass of %UnitTest.TestCase that your unit tests will extend. This code could live somewhere else too, but it's useful to be able to say:
and not have to remember/type the test suite format and /nodelete. Sample implementation:
This allows you to specify an instance of a %UnitTest.Manager to capture the test results in, which is useful if you're running a bunch of specific unit test classes (like you suggested, from a Studio project). My team organizes tests in packages rather than in projects, which makes more sense for us.
Next up, here's our %UnitTest.Manager subclass that works with the %UnitTest.TestCase subclass shown above, allowing all the classes in a particular namespace or package (or, really, with class names that contain a particular string) to be run without deleting them afterward:
This could probably be tweaked to use a project instead without too much work, but I think packages are a more reasonable way of organizing unit tests.
I'm only seeing this post now... Great source of information!
Now I wish I had more practice... But this is close to what I want to do.
Don't you want to contribute to the project? :p