sandopolus
unread,Dec 1, 2009, 1:26:07 PM12/1/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to testng-dev
In the testng.xml file when the package element is supplied with a
regex like <package name=".*"/> the ClassHelper will error due to an
extra "." being put at the front of the full class name. This causes
it not to find the class because it is looking for the wrong name when
using TestNG v5.10.
I haven't checked out the trunk code and checked that it still has
this bug, but from looking at the code it looks like it is still
present. I have some testng log output and a fix to stop it from
happening if it hasn't already been identified below.
Below is the trimmed down logs that i am getting out when this error
happens.
[PackageUtils] Found class ConfigurationPageTest, seeing it if it's
included or excluded
[PackageUtils] ... Including class ConfigurationPageTest
[TestRunner] Running the tests in 'JUnit Tests' with parallel
mode:false
[RunInfo] Adding method selector:
org.testng.internal.XmlMethodSelector@1172e08 priority: 10
[SuiteRunner] Created 1 TestRunners
[TestRunner] Running test JUnit Tests on 0 classes, included groups:
[] excluded groups:[]
[ClassHelper] Could not
instantiate .com.omnifone.musicstation.server.ccc.ConfigurationPageTest: .com.omnifone.musicstation.server.ccc.ConfigurationPageTest
[ClassHelper] Could not
instantiate .com.omnifone.musicstation.server.ccc.ConfigurationPageTest: /
com/omnifone/musicstation/server/ccc/ConfigurationPageTest
org.testng.TestNGException:
Cannot find class in
classpath: .com.omnifone.musicstation.server.ccc.ConfigurationPageTest
at org.testng.xml.XmlClass.getSupportClass(XmlClass.java:55)
at org.testng.internal.Utils.xmlClassesToClasses(Utils.java:
79)
at org.testng.TestRunner.privateRunJUnit(TestRunner.java:520)
at org.testng.TestRunner.run(TestRunner.java:483)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:332)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:
327)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:299)
at org.testng.SuiteRunner.run(SuiteRunner.java:204)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:912)
at org.testng.TestNG.runSuitesLocally(TestNG.java:876)
at org.testng.TestNG.run(TestNG.java:784)
at org.testng.TestNG.privateMain(TestNG.java:949)
at org.testng.TestNG.main(TestNG.java:922)
I have tracked this down to the org.testng.internal.PackageUtils
class.
The problem seems to be in the findClassesInDirPackage method where it
recursively calls through the directories by setting the packageName
argument to packageName + "." + file.getName().
When a .* regex is given the packageName argument is originally an
empty string and so this then causes a . to be put at the front of the
class name when the includeOrExcludeClass method adds the full class
name to the list of classes.
My current fix for the code is to change the below line (Currently
line 185 in the trunk)
findClassesInDirPackage(packageName + "." + file.getName(), included,
excluded, file.getAbsolutePath(), recursive, classes);
To
String recursivePackageName= file.getName();
if (packageName.length() > 0) {
recursivePackageName = packageName + "." + recursivePackageName;
}
findClassesInDirPackage(recursivePackageName, included, excluded,
file.getAbsolutePath(), recursive, classes);