[Cppunit-devel] TestRegistry... What use for it?
Brought to you by:
blep
From: Baptiste L. <gai...@fr...> - 2001-04-18 16:19:36
|
As you may know, I've done the CppUnit Windows Edition. Well, I discussed with Bastiaan who have recently taken up the administration of the project and we'll be working in integrating things. The windows support will come (this version of cppunit is supposed to be cross-platform!). When I told him about the TestRegistry bug fix. He told me "the best bug fix would be to kill it. I don't see the use of a static registry. JUnit hasn't one either anyway." Let's not args about the actual implementation, but about the use for it. First, here is how the "thing" works: 1) the TestCase constructor automatically register the test case to the TestRegistry. 2) before running all the test, you're supposed to retreive all the registred test using the getAllTests() method and pass them to the test runner. Point 1 is definitely a no no, here is why: In the traditionnal implementation of your static suite method(): suite->addTest( new TestCaller<MyTestCase>( "testSomething", testSomething ) ); The problem ? TestCaller creates a new instance of MyTestCase. So what happens: the new instance is registered, and the TestCaller, being itself a TestCase is also registered!!! You get two tests registered when only one was supposed to be! Even worth, in the example, the test case are static variables, and guess what happen when the TestRegistry try to delete them !!! Conclusion: exterminates the "automatic registration", or at least remove it from TestCase and pull it down (I really don't see any use of an automatic registration of that form). Point 2: That's one is actually a nice thing, setting up your test runner look like this: TestRunner runner; TestRegistry registry = TestRegistry::getRegistry() runner.addTests( registry.getAllTests() ); runner.run(); You do the code once and don't need to update it. The only requierement is that you have your tests correctly registered. Of course that is the hard part. But suppose it works, it would be rather useful (who never forget to add a test either to a suite or to the test runner ?) The problem is that the registered test would be simple TestCaller, no possibility to say run suite XYZ (which would be matching the part your refactoring). Well, who said the registered test needed to be TestCaller, you can register suite. If only the top level suites would be registered, then everything would work fine. How to do that ? I don't know yet, but I'm playing with some stuff. I've already implemented a way to have suite for each unit test class registered (which is enough for my need at the current time), and I will try to extend the idea to build a real hieararchy. So my conclusion would be to leave it alone, it may be of use for some, but don't make it mandatory. It is a non core "feature" and should not be mandatory. Until next time, for the suite auto-registration... Baptiste. --- Baptiste Lepilleur <gai...@fr...> http://gaiacrtn.free.fr/index.html Language: English, French |