Excluding inner test-classes

13 views
Skip to first unread message

Carsten

unread,
Nov 2, 2009, 12:23:52 PM11/2/09
to testng-users
Hi,

we use factory classes to generate sample test-cases, often with inner
classes.

TestNG seems not to like inner test-classes like

public class TestCaseFactory
{
class MyTestClass
{
@Test
public void testAll()
{
}
}

@Factory
public Object[] createTestCases()
{
Object[] testCases = new Object[1];
testCases[0] = new MyTestClass() // create an inner class
- testng tries to execute this inner class
{
};
return testCases;
}
}

When executing the Factory class (which is not supposed to be a test
at all) i get the following error message:

java.lang.IllegalAccessException: Class
org.testng.internal.MethodHelper can not access a member of class
test.recommind.utility.TestCaseFactory$MyTestClass with modifiers
"public"
... Removed 20 stack frames

We still use testng 5.8 and i debugged into it. Filtering these inner
classes in ClassHelper solved the problem for us:
public static <T> T tryOtherConstructor(Class<T> declaringClass)
{
if (declaringClass.getModifiers() == 0)
{
return null;
}
// remaining code...
}

The class modifiers are defined here:
http://java.sun.com/docs/books/jvms/first_edition/html/ClassFile.doc.html#21045

I couldn't find modifier 0, but it applies to inner classes. Is it
possible to add the code fragment to TestNG? Then we do not have to
use custom testng-code.

Thanks,
Carsten

Cédric Beust ♔

unread,
Nov 2, 2009, 12:41:26 PM11/2/09
to testng...@googlegroups.com
Hi Carsten,

This sounds reasonable, can you send me a diff of your patch?  I'll incorporate it.

--
Cédric

Carsten

unread,
Nov 2, 2009, 1:16:18 PM11/2/09
to testng-users
Hi Cedric,

I sent the diff file by email.

Thanks,
Carsten


On Nov 2, 6:41 pm, Cédric Beust ♔ <cbe...@google.com> wrote:
> Hi Carsten,
>
> This sounds reasonable, can you send me a diff of your patch?  I'll
> incorporate it.
>
> --
> Cédric
>
> On Mon, Nov 2, 2009 at 9:23 AM, Carsten
> <carsten.guberna...@googlemail.com>wrote:
> >http://java.sun.com/docs/books/jvms/first_edition/html/ClassFile.doc....
Reply all
Reply to author
Forward
0 new messages