Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Re: -> IllegalAccessError using JUnit PDE Test
Re: -> IllegalAccessError using JUnit PDE Test [message #91748] Wed, 03 September 2003 12:34 Go to next message
Eric Estievenart is currently offline Eric EstievenartFriend
Messages: 64
Registered: July 2009
Member
Sorry this may not be linked to the original news item
( http://dev.eclipse.org/newslists/news.eclipse.tools.jdt/msg0 3201.html),
byt either my reader or the news server refuse to show too old items.

It would be great if a test plugin could access default methods
from a production plugin same package...

Has someone had any update on that ?

Has a bug been logged (would be glad to vote for it) ?

For now I'm doing it with ugly public methods prefixed with "junit" so that
I can see at least how they are used, but the pde junit plugin should
allow doing this kind of stuff.

Thx for any info

--Steve
Re: -> IllegalAccessError using JUnit PDE Test [message #91778 is a reply to message #91748] Wed, 03 September 2003 13:32 Go to previous messageGo to next message
Martin Kersten is currently offline Martin KerstenFriend
Messages: 306
Registered: July 2009
Senior Member
> Sorry this may not be linked to the original news item
> ( http://dev.eclipse.org/newslists/news.eclipse.tools.jdt/msg0 3201.html),
> byt either my reader or the news server refuse to show too old items.
>
> It would be great if a test plugin could access default methods
> from a production plugin same package...
>
> Has someone had any update on that ?
Since it was me who started the topic here is what works great:
Just add a second source folder called src-test and place your tests
in there. Your test code is now running within the same plugin as
your normal one. (Use the same bin directory for both). Now you
have access to everything. To get the product simply remove all
unnecessary classes using tools or just remove the src-test folder
(use a second workbench on that).

Hope that helps ;)


Martin (Kersten)
Re: -> IllegalAccessError using JUnit PDE Test [message #92122 is a reply to message #91778] Thu, 04 September 2003 08:51 Go to previous messageGo to next message
Eric Estievenart is currently offline Eric EstievenartFriend
Messages: 64
Registered: July 2009
Member
Yes I had seen this trick, but it does not suit me perfectly,
for the following reasons:

- First having test & prod code in the same project may be dangerous
if the test code goes into production (!)

- Then the test code depends on specific support classes, which are shared
between various testing projects, and the prod code has not to depend
on them, so the dependencies would be different whether we
are compiling for prod or development...

- And now the test project is a real plugin, which allows to perform
specific testing actions, and its actions are not to be in the production
plugin.xml

I'll do with ugly public methods for now, but it would be ok
if there was some kind of "friend plugins" declaration possibility
in the plugin.xml. Even if this is a real security issue, but for me
it is the only real clean way. (And security could anyway be enforced
through signatures or something like that)


--Steve


On Wed, 3 Sep 2003 15:32:58 +0200, Martin Kersten

> Since it was me who started the topic here is what works great:
> Just add a second source folder called src-test and place your tests
> in there. Your test code is now running within the same plugin as
> your normal one. (Use the same bin directory for both). Now you
> have access to everything. To get the product simply remove all
> unnecessary classes using tools or just remove the src-test folder
> (use a second workbench on that).
>
> Hope that helps ;)
>
>
> Martin (Kersten)
>
>
>
Re: -> IllegalAccessError using JUnit PDE Test [message #92654 is a reply to message #92122] Fri, 05 September 2003 06:10 Go to previous messageGo to next message
Martin Kersten is currently offline Martin KerstenFriend
Messages: 306
Registered: July 2009
Senior Member
One think that works also is to subclass the class on which you want to
have protected access level. And you can also use the none-pde test
to test models and stuff. You know using the none-pde test suite
gives you the protected level as well ;) Thats what I ve done before
merging both.

Martin (Kersten)


"Eric Estievenart" <eric.estievenart@peregrine.com> schrieb im Newsbeitrag
news:opruyv8sii9ck0a6@localhost...
>
> Yes I had seen this trick, but it does not suit me perfectly,
> for the following reasons:
>
> - First having test & prod code in the same project may be dangerous
> if the test code goes into production (!)
>
> - Then the test code depends on specific support classes, which are shared
> between various testing projects, and the prod code has not to depend
> on them, so the dependencies would be different whether we
> are compiling for prod or development...
>
> - And now the test project is a real plugin, which allows to perform
> specific testing actions, and its actions are not to be in the
production
> plugin.xml
>
> I'll do with ugly public methods for now, but it would be ok
> if there was some kind of "friend plugins" declaration possibility
> in the plugin.xml. Even if this is a real security issue, but for me
> it is the only real clean way. (And security could anyway be enforced
> through signatures or something like that)
>
>
> --Steve
>
>
> On Wed, 3 Sep 2003 15:32:58 +0200, Martin Kersten
>
> > Since it was me who started the topic here is what works great:
> > Just add a second source folder called src-test and place your tests
> > in there. Your test code is now running within the same plugin as
> > your normal one. (Use the same bin directory for both). Now you
> > have access to everything. To get the product simply remove all
> > unnecessary classes using tools or just remove the src-test folder
> > (use a second workbench on that).
> >
> > Hope that helps ;)
> >
> >
> > Martin (Kersten)
> >
> >
> >
>
>
Re: -> IllegalAccessError using JUnit PDE Test [message #92669 is a reply to message #92654] Fri, 05 September 2003 09:58 Go to previous messageGo to next message
Martin Kersten is currently offline Martin KerstenFriend
Messages: 306
Registered: July 2009
Senior Member
> One think that works also is to subclass the class on which you want to
> have protected access level. And you can also use the none-pde test
> to test models and stuff. You know using the none-pde test suite
> gives you the protected level as well ;) Thats what I ve done before
> merging both.

Mostly I used static inner subclassing. (Orginally used testing abstract
classes by providing a testing implementation).

class MyTestCase extends TestCase {

public void testProtectedMethod() {
ToTest toTest=new MyToTest();
toTest.publicMethod();
((MyToTest)toTest).protectedMethod();
}
private static MyToTest extends ToTest {
}
}

So the construction differs and a cast has to be
done to call a protected method. Or if you have to
test at protected level all the time you can change the
type as well. AnIdea would be introducing a naming
convention. Like adding a '_' to the inner class to
ease code understandment.

class MyTestCase extends TestCase {

public void testProtectedMethod() {
ToTest_ toTest=new ToTest_();
toTest.publicMethod();
toTest.protectedMethod();
}
private static ToTest_ extends ToTest {
}
}

I think this wouldn't be such a big problem. The
problems start when to test indirect. Like
toTest.getPart().packageMethod();

This is untestable. But I guess it is not that much of use
to test packageMethods at this level.


Did you tested this behaviour using the current Eclipse 3.0
milestone release? If it isn't providing that level of access or
any method to gain it, I would like to file in a bug report.


Martin (Kersten)

PS: I tested the export setting on jar libraries of the plugin
and it doesn't change the available access level.
Re: -> IllegalAccessError using JUnit PDE Test [message #94156 is a reply to message #92669] Wed, 10 September 2003 18:06 Go to previous messageGo to next message
Eric Estievenart is currently offline Eric EstievenartFriend
Messages: 64
Registered: July 2009
Member
On Fri, 5 Sep 2003 11:58:30 +0200, Martin Kersten
<Martin.Kersten@student.uni-magdeburg.de> wrote:

>> One think that works also is to subclass the class on which you want to
>> have protected access level. And you can also use the none-pde test
>> to test models and stuff. You know using the none-pde test suite
>> gives you the protected level as well ;) Thats what I ve done before
>> merging both.

Well, it is a bit painful, and even more when you don't control
the class allocation, because for example you are testing a class
instance which has been allocated by another, generally indirectly.

What I want is really to access default members, which were generally
private and promoted to 'default' for this purpose (not that I am
paranoid ;-)

This also must be simple and straightforward, because people already
tend not to make tests at all (sic).

> I think this wouldn't be such a big problem. The
> problems start when to test indirect. Like
> toTest.getPart().packageMethod();
>
> This is untestable. But I guess it is not that much of use
> to test packageMethods at this level.

I let you imagine that my test is like :
. connect to a database
. execute many commands to display forms
. lookup at the forms internals
. ...

so as you say, it is not testable using what you preconize ;-)

There is also another way, which is to make all members of the tested
classes accessible through reflection in the test
project. It does not impact the production code, and does not
clutter the production classes with widely accessible test methods.

> Did you tested this behaviour using the current Eclipse 3.0
> milestone release? If it isn't providing that level of access or
> any method to gain it, I would like to file in a bug report.

I did not test it against 3.0, maybe I'll try next week.
For me there are 2 bugs :
- The IllegalAccessError
- The fact that eclipse let the test project compile.

--Steve
Re: -> IllegalAccessError using JUnit PDE Test [message #95822 is a reply to message #94156] Mon, 15 September 2003 16:38 Go to previous message
Martin Kersten is currently offline Martin KerstenFriend
Messages: 306
Registered: July 2009
Senior Member
Hi Eric,

> This also must be simple and straightforward, because people already
> tend not to make tests at all (sic).
Thats why I use test first. First write the test then the implementation ;)
Its more fun, its more secure and nearly 100% test covered
(beside some execution paths ;)

> > This is untestable. But I guess it is not that much of use
> > to test packageMethods at this level.
>
> I let you imagine that my test is like :
> . connect to a database
> . execute many commands to display forms
> . lookup at the forms internals
> . ...
>
> so as you say, it is not testable using what you preconize ;-)
Thats a 100% mock situation ;) Think about extending the forms
and check every single step that is done on them. You know something
like if an label is added, check the label and verfiy it. Was it expected
there? etc.

Or think about a logger or compare a precalculated and manually
checked result against the result of your test.

> There is also another way, which is to make all members of the tested
> classes accessible through reflection in the test
> project. It does not impact the production code, and does not
> clutter the production classes with widely accessible test methods.
Reflection didn't worked for me here. Throws also IllegalAccessException
here (checked it ;).

> > Did you tested this behaviour using the current Eclipse 3.0
> > milestone release? If it isn't providing that level of access or
> > any method to gain it, I would like to file in a bug report.
>
> I did not test it against 3.0, maybe I'll try next week.
> For me there are 2 bugs :
> - The IllegalAccessError
> - The fact that eclipse let the test project compile.

Well the illegal access exception /error is a runtime behaviour
special to the way plugins are loaded and classes are shared.
The compile without error isn't a bug. There are implementations
possible which run your code well. So the compiler is right to
declare it as '100% correct' java code ;)

Martin (Kersten)
Previous Topic:How to set up JBoss IDE 1.2 inside Eclipse 3.0
Next Topic:PostgreSQL JDBC Driver Not Found
Goto Forum:
  


Current Time: Tue Aug 27 23:52:54 GMT 2024

Powered by FUDForum. Page generated in 0.04078 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top