Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » JUnit test setup?
JUnit test setup? [message #241512] Fri, 14 May 2004 16:59 Go to next message
Eclipse UserFriend
I've read through Beck and Gamma's 'Contributing to Eclipse' and, with
their help, I've created a plugin which runs JUnit tests in an incremental
builder. This is very promising stuff.

However. In order to keep code and binaries clearly separated, all tests
for the plugin 'com.company.foo' reside in a plugin
'com.company.foo.tests'. This leads to an annoying problem when I want to
test the base plugin class for com.company.foo, namely, the plugin class
hasn't been instantiated.

According to the documentation, implementing the singleton pattern and
accessing the plugin class via a 'getInstance' method is guaranteed to
alwasy return an initialize instance of the plugin class --- but my
experience shows otherwise (unless it matters what the method name is??
We actually access the singleton via a static 'getDefault' method).

So, I next attempted to guarantee that 'getDefault' would return an
initialized instance by adding in logic which would check whether the
single were null, and if it is, initializing it by calling
'Platform.getPlugin(<pluginID>)'. This, too, is failing.

So, does anyone have any suggestions as to how I can maintain the desired
separation of 'com.company.foo' from 'com.company.foo.tests' and still get
eevrything to work?

Thanks,
Re: JUnit test setup? [message #241595 is a reply to message #241512] Sat, 15 May 2004 12:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: fuhrman.videoSANS_SPAMtron.ca

"David Bailey" <david.bailey@lawson.com> wrote in message
news:c83buq$osa$1@eclipse.org...
> According to the documentation, implementing the singleton pattern and
> accessing the plugin class via a 'getInstance' method is guaranteed to
> alwasy return an initialize instance of the plugin class --- but my
> experience shows otherwise (unless it matters what the method name is??
> We actually access the singleton via a static 'getDefault' method).

It's a convention to use getInstance() but as long as you're calling this
method from the singleton, it shouldn't matter. I admit I'm unaware of this
being a constraint for the plugin API. Seems it would be in an interface
that you'd have to implement, if it were a constraint.

> So, I next attempted to guarantee that 'getDefault' would return an
> initialized instance by adding in logic which would check whether the
> single were null, and if it is, initializing it by calling
> 'Platform.getPlugin(<pluginID>)'. This, too, is failing.

Failing how? getDefault() isn't returning an instance? I don't actually know
much about the tool environment, but I can help with how Singleton
can/should be implemented:

For a singleton of class X:

public class X {
/* experiment with Platform.getPlugin(<pluginID>) here instead of new? */
private static X instance = new X();
private X () {/* private constructor */ }
public static X getInstance() {
return instance;
}
....
}
Re: JUnit test setup? [message #241771 is a reply to message #241595] Mon, 17 May 2004 11:50 Go to previous message
Eclipse UserFriend
Platform.getPlugin(<pluginID>) returns null. And while you're correct that,
in general, I could handle this by instantiating a 'new Plugin' in the static
'getDefault' method, the Eclipse javadoc warns against clients directly
instantiating plugin classes.

Christopher Fuhrman wrote:

> "David Bailey" <david.bailey@lawson.com> wrote in message
> news:c83buq$osa$1@eclipse.org...
> > According to the documentation, implementing the singleton pattern and
> > accessing the plugin class via a 'getInstance' method is guaranteed to
> > alwasy return an initialize instance of the plugin class --- but my
> > experience shows otherwise (unless it matters what the method name is??
> > We actually access the singleton via a static 'getDefault' method).

> It's a convention to use getInstance() but as long as you're calling this
> method from the singleton, it shouldn't matter. I admit I'm unaware of this
> being a constraint for the plugin API. Seems it would be in an interface
> that you'd have to implement, if it were a constraint.

> > So, I next attempted to guarantee that 'getDefault' would return an
> > initialized instance by adding in logic which would check whether the
> > single were null, and if it is, initializing it by calling
> > 'Platform.getPlugin(<pluginID>)'. This, too, is failing.

> Failing how? getDefault() isn't returning an instance? I don't actually know
> much about the tool environment, but I can help with how Singleton
> can/should be implemented:

> For a singleton of class X:

> public class X {
> /* experiment with Platform.getPlugin(<pluginID>) here instead of new? */
> private static X instance = new X();
> private X () {/* private constructor */ }
> public static X getInstance() {
> return instance;
> }
> ....
> }
Previous Topic:Drag&Drop from Resource Navigator to Eclipse editor
Next Topic:Window>Customize Perspective>Other
Goto Forum:
  


Current Time: Sun Jun 01 04:07:48 EDT 2025

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

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

Back to the top