Possible bug with regex in the package element

17 views
Skip to first unread message

sandopolus

unread,
Dec 1, 2009, 1:26:07 PM12/1/09
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);

Cédric Beust ♔

unread,
Dec 1, 2009, 4:34:07 PM12/1/09
to testn...@googlegroups.com, sando...@gmail.com
Good catch, I fixed it in the beta, can you please try it?

http://testng.org/beta

--
Cédric





--

You received this message because you are subscribed to the Google Groups "testng-dev" group.
To post to this group, send email to testn...@googlegroups.com.
To unsubscribe from this group, send email to testng-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.





sandopolus

unread,
Dec 2, 2009, 5:32:48 AM12/2/09
to testng-dev
I have tested the 5.11 beta and the problem has been fixed.

Ta

On Dec 1, 9:34 pm, Cédric Beust ♔ <cbe...@google.com> wrote:
> Good catch, I fixed it in the beta, can you please try it?
>
> http://testng.org/beta
>
> --
> ***Cédric
> *
> > testng-dev+...@googlegroups.com<testng-dev%2Bunsu...@googlegroups.com>
> > .

borojevic

unread,
Dec 2, 2009, 7:39:11 AM12/2/09
to testng-dev
Can I just add small "issue" that is probably not an issue.
When you specify package name with the white space at the end or
begining, tests are not found, maybe some triming would help or it
might be that it is better like this... ?

Cheers,
Aleksandar
> > > testng-dev+...@googlegroups.com<testng-dev%2Bunsubscribe@googlegrou ps.com>
Reply all
Reply to author
Forward
0 new messages