You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're having an issue with the way classes are handled when building a TestSuite.
We have a hierarchy of test classes that eventually derive from testcase. Some of the classes in the hierarchy are abstract, but other aren't. When the TestSuite is built, the non-abstract classes are added to the TestSuite and an instance of them is constructed. Those classes don't have test methods, so only the constructor is run. The problem is that their constructors perform a long initialization, which is run multiple times (once for each 'parent' class created).
Our hierarchy of classes is something like:
abstract class BaseTest extends UnitTestCase {}
class CommonTest extends BaseTest {}
class TestWithDb extends CommonTest {}
class ATest extends TestWithDb {}
When we try to run ATest, three instances are created: one of ATest (as expected), but also one of TestWithDb and one of CommonTest.
My question is what is the rationale behind it? If the class of the test has a parent class, why is the latter instantiated on its own?
scrapeClassesFromFile(): finds all the classes of our hierarchy.
selectRunnableTests(): marks as ignored only abstract classes
createSuiteFromClasses(): ignores only the parent of ignored classes, creates one instance of the remaining ones.
Regards,
Alejandro
The text was updated successfully, but these errors were encountered:
Hi,
We're having an issue with the way classes are handled when building a TestSuite.
We have a hierarchy of test classes that eventually derive from testcase. Some of the classes in the hierarchy are abstract, but other aren't. When the TestSuite is built, the non-abstract classes are added to the TestSuite and an instance of them is constructed. Those classes don't have test methods, so only the constructor is run. The problem is that their constructors perform a long initialization, which is run multiple times (once for each 'parent' class created).
Our hierarchy of classes is something like:
abstract class BaseTest extends UnitTestCase {}
class CommonTest extends BaseTest {}
class TestWithDb extends CommonTest {}
class ATest extends TestWithDb {}
When we try to run ATest, three instances are created: one of ATest (as expected), but also one of TestWithDb and one of CommonTest.
My question is what is the rationale behind it? If the class of the test has a parent class, why is the latter instantiated on its own?
The sequence of the code is:
In SimpleFileLoader:
}
scrapeClassesFromFile(): finds all the classes of our hierarchy.
selectRunnableTests(): marks as ignored only abstract classes
createSuiteFromClasses(): ignores only the parent of ignored classes, creates one instance of the remaining ones.
Regards,
Alejandro
The text was updated successfully, but these errors were encountered: