Skip to main content



      Home
Home » Eclipse Projects » Eclipse 4 » JUnit Plug-in testing
JUnit Plug-in testing [message #1717755] Wed, 16 December 2015 09:15 Go to next message
Eclipse UserFriend
Dear list,

I am running JUnit tests inside the Eclipse OSGi pool (with bundle contexts, OSGi components, etc.) is by using the JUnit Plug-in Test run/debug configuration type.

Is this the good approach for enabling functional JUnit tests in my Eclipse application?

Thanks,
-Piero
Re: JUnit Plug-in testing [message #1717771 is a reply to message #1717755] Wed, 16 December 2015 10:46 Go to previous messageGo to next message
Eclipse UserFriend
Yup!
Re: JUnit Plug-in testing [message #1717835 is a reply to message #1717755] Thu, 17 December 2015 03:26 Go to previous messageGo to next message
Eclipse UserFriend
Yes! However, I would recommend to do plain JUnit tests whereever
possible. OSGi test are slower and require more maintenance, e.g. you
have to maintain the run config and the tycho config.
As an example, if you want to test OSGi services, which depend on each
other, you can simply instanciate and wire them manually in plain JUnit.
This way, you have full control on which components are used and which
are mocked.
I would recommend to use OSGi for integration tests only and test the
behavior mainly with plain JUnit tests. This will typically also improve
your architecture as it makes your components less dependent on OSGi.

Best regards

Jonas


Am 16.12.2015 um 15:15 schrieb Piero Campalani:
> Dear list,
>
> I am running JUnit tests inside the Eclipse OSGi pool (with bundle
> contexts, OSGi components, etc.) is by using the JUnit Plug-in Test
> run/debug configuration type.
>
> Is this the good approach for enabling functional JUnit tests in my
> Eclipse application?
>
> Thanks,
> -Piero
>


--
--

Jonas Helming

Get professional Eclipse developer support:

http://eclipsesource.com/en/services/developer-support/
Re: JUnit Plug-in testing [message #1717854 is a reply to message #1717835] Thu, 17 December 2015 06:49 Go to previous messageGo to next message
Eclipse UserFriend
Dear Jonas,
Thanks for your very welcome opinion.
I'm not sure I understand how I can achieve it anyway..

Many bundles here which depend on having the Eclipse context in order to resolve resources like properties files, configuration files, icons, etc.

So essentially my services break when their bundle activator provides no context.

Any further suggestion?

Thanks a zillion,
-Piero
Re: JUnit Plug-in testing [message #1717969 is a reply to message #1717854] Fri, 18 December 2015 05:26 Go to previous messageGo to next message
Eclipse UserFriend
Are we talking about the BundleContext oder the IEclipseContext?

Am 17.12.2015 um 12:49 schrieb Piero Campalani:
> Dear Jonas,
> Thanks for your very welcome opinion.
> I'm not sure I understand how I can achieve it anyway..
>
> Many bundles here which depend on having the Eclipse context in order to
> resolve resources like properties files, configuration files, icons, etc.
>
> So essentially my services break when their bundle activator provides no
> context.
>
> Any further suggestion?
>
> Thanks a zillion,
> -Piero


--
--

Jonas Helming

Get professional Eclipse developer support:

http://eclipsesource.com/en/services/developer-support/
Re: JUnit Plug-in testing [message #1717977 is a reply to message #1717969] Fri, 18 December 2015 06:35 Go to previous messageGo to next message
Eclipse UserFriend
I suppose the BundleContext because he is talking about resource loading.

When resources come into play things are different in OSGi and plain Java. In the past I worked around that by providing different ways to load resources in a JUnit test and in production. But that was basically a misconception on my side.

Since you need to test the resource loading in the OSGi context because you need to ensure that it is working in your product, this needs to be seen as an integration test, and therefore be executed as JUnit Plug-in test. But to be able to test the functionality without the OSGi integration you could think about implementing a service that provides the resource. And for plain JUnit testing you could mock that resource service with something that returns a resource from the classloader for example. Or you implement the resource loading as a protected method in your service and mock the method then.
Re: JUnit Plug-in testing [message #1718190 is a reply to message #1717969] Mon, 21 December 2015 02:36 Go to previous message
Eclipse UserFriend
Quote:
Are we talking about the BundleContext oder the IEclipseContext?


_Bundle_ context (from which I need the org.osgi.framework.Bundle in the end for my FileLocator).
Previous Topic:RCP tycho build gives issue regarding Gradle
Next Topic:LinkedPosition iteration not working in e4 application
Goto Forum:
  


Current Time: Fri Jul 25 21:06:32 EDT 2025

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

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

Back to the top