Excluding inner test-classes

View: New views
3 Messages — Rating Filter:   Alert me  

Excluding inner test-classes

by Carsten-21 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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


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


Re: Excluding inner test-classes

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.gubernator@...> wrote:

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







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


Re: Excluding inner test-classes

by Carsten-21 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi Cedric,

I sent the diff file by email.

Thanks,
Carsten


On Nov 2, 6:41 pm, Cédric Beust ♔ <cbe...@...> 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...@...>wrote:
>
>
>
> > 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....
>
> > 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---