Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » How to create and run JUnit tests on FX plugins?
How to create and run JUnit tests on FX plugins? [message #1737769] Tue, 12 July 2016 18:04 Go to next message
John Bodkin is currently offline John BodkinFriend
Messages: 39
Registered: November 2011
Member
How do you perform JUnit tests of plugins?

I created a fragment project that performs a non-UI test on the Controller class of the host plugin. The test is just instantiating the Controller class and then assertNotNull on the variable. The Controller class imports javafx.beans.value.ChangeListener. If I right click the test class and select Run As->JUnit test it completes successfully. If I select Run As->JUnit Plug-in Test it produces the error: java.lang.NoClassDefFoundError: javafx/beans/value/ChangeListener.

When I run the Maven-Tycho (0.25.0) build it also produces the error:
java.lang.NoClassDefFoundError: javafx/beans/value/ChangeListener

I'm running from e(fx)clipse 4.6.0/2.4.0 on Windows 7.

I tried installing the jfxrt.jar file in the .m2 repo. I visited other posts that talked about Jemmy but Jemmy is not in my target and we were not trying to do UI tests and a coworker says Jemmy has been discontinued. I tried altering the run configuration by using plugins listed instead of the default setting and check all the plugins in the list.

Re: How to create and run JUnit tests on FX plugins? [message #1737773 is a reply to message #1737769] Tue, 12 July 2016 18:35 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You need to pass "-Dorg.osgi.framework.bundle.parent=ext" in the
VM-Arguments

Tom

On 12.07.16 20:04, John Bodkin wrote:
> How do you perform JUnit tests of plugins?
>
> I created a fragment project that performs a non-UI test on the
> Controller class of the host plugin. The test is just instantiating the
> Controller class and then assertNotNull on the variable. The Controller
> class imports javafx.beans.value.ChangeListener. If I right click the
> test class and select Run As->JUnit test it completes successfully. If I
> select Run As->JUnit Plug-in Test it produces the error:
> java.lang.NoClassDefFoundError: javafx/beans/value/ChangeListener.
>
> When I run the Maven-Tycho (0.25.0) build it also produces the error:
> java.lang.NoClassDefFoundError: javafx/beans/value/ChangeListener
>
> I'm running from e(fx)clipse 4.6.0/2.4.0 on Windows 7.
>
> I tried installing the jfxrt.jar file in the .m2 repo. I visited other
> posts that talked about Jemmy but Jemmy is not in my target and we were
> not trying to do UI tests and a coworker says Jemmy has been
> discontinued. I tried altering the run configuration by using plugins
> listed instead of the default setting and check all the plugins in the
> list.
>
>
Re: How to create and run JUnit tests on FX plugins? [message #1737775 is a reply to message #1737773] Tue, 12 July 2016 19:13 Go to previous messageGo to next message
John Bodkin is currently offline John BodkinFriend
Messages: 39
Registered: November 2011
Member
Thanks for that. That moved things forward but now I'm getting a NoClassDefFoundError for a class that is in a jar that is in a plugin that is part of the overall project. All plugins use it as a import package rather than a required plugin. This is a desired design choice.

I tried alternated settings to that -D i.e. boot (which is the default), app, framework and I set it back to ext.

Thanks for the help
Re: How to create and run JUnit tests on FX plugins? [message #1737779 is a reply to message #1737775] Tue, 12 July 2016 19:54 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Your problem does not sound like it is a problem with -D as this only
configures the parent-classloader for bundles. Did you try checking
"Clear configuration area before launching" on the Configuration-Tab
inside your launch config? Does the MANIFEST.MF hold the inner-jar?

BTW: Using import-package is the preferred way anyways!

Tom

On 12.07.16 21:13, John Bodkin wrote:
> Thanks for that. That moved things forward but now I'm getting a
> NoClassDefFoundError for a class that is in a jar that is in a plugin
> that is part of the overall project. All plugins use it as a import
> package rather than a required plugin. This is a desired design choice.
>
> I tried alternated settings to that -D i.e. boot (which is the default),
> app, framework and I set it back to ext.
>
> Thanks for the help
Re: How to create and run JUnit tests on FX plugins? [message #1737781 is a reply to message #1737779] Tue, 12 July 2016 20:08 Go to previous messageGo to next message
John Bodkin is currently offline John BodkinFriend
Messages: 39
Registered: November 2011
Member
It is set to "Clear configuration area before launching" on the Configuration-Tab.

The MANIFEST.MF does hold the inner-jar. "Bundle-ClassPath: My.jar"

The junit test fragment project can see every project in the workspace EXCEPT the one that contains the jar in question (My.jar). So I'm unable to add the library to the list of required plugins.
Re: How to create and run JUnit tests on FX plugins? [message #1737782 is a reply to message #1737779] Tue, 12 July 2016 20:18 Go to previous messageGo to next message
John Bodkin is currently offline John BodkinFriend
Messages: 39
Registered: November 2011
Member
I added every exported package from our library plugin to the junit test fragment project as imported packages and got a successful run from the Run As->JUnit Plugin test.

I put the -D on the VM args of the Maven-Tycho build and it did not work. Is there a different way of doing this for the Maven build?
Re: How to create and run JUnit tests on FX plugins? [message #1737784 is a reply to message #1737782] Tue, 12 July 2016 20:41 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Well how do you run the tests in maven? My setups look similar to this:

> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
> <modelVersion>4.0.0</modelVersion>
> <name>.....</name>
> <groupId>....</groupId>
> <artifactId>....</artifactId>
> <packaging>eclipse-test-plugin</packaging>
> ...
> <build>
> <plugins>
> <plugin>
> <groupId>org.eclipse.tycho</groupId>
> <artifactId>tycho-surefire-plugin</artifactId>
> <version>${tycho-version}</version>
> <configuration>
> <testSuite>bla.bla.tests</testSuite>
> <testClass>bla.bla.tests.SearchTest</testClass>
> <useUIHarness>false</useUIHarness>
> <useUIThread>false</useUIThread>
> <argLine>-Dorg.osgi.framework.bundle.parent=ext</argLine>
> <appArgLine>-consoleLog -nosplash</appArgLine>
> <application>org.eclipse.pde.junit.runtime.coretestapplication</application>
> </configuration>
> </plugin>

and then things work like they should.

Tom

On 12.07.16 22:18, John Bodkin wrote:
> I added every exported package from our library plugin to the junit test
> fragment project as imported packages and got a successful run from the
> Run As->JUnit Plugin test.
>
> I put the -D on the VM args of the Maven-Tycho build and it did not
> work. Is there a different way of doing this for the Maven build?
Re: How to create and run JUnit tests on FX plugins? [message #1737786 is a reply to message #1737784] Tue, 12 July 2016 21:19 Go to previous messageGo to next message
John Bodkin is currently offline John BodkinFriend
Messages: 39
Registered: November 2011
Member
We are using Tycho 25 so we did not create a POM in the fragment project. Are root POM references the POM in the tests directory which lists the modules in the tests directory.
Since Tycho 25 allows for pomless builds I assumed that meant the test bundles could also be pomless as well even though feature projects still require POMs. The test is executed during the build but the previously mentioned NoClassDefFoundError occurs.

I'll create a POM in the fragment project and see if that fixes the issue tomorrow.

Thanks again for the help.

If you have a link to documentation that I could have used to learn this that would be appreciated.

Re: How to create and run JUnit tests on FX plugins? [message #1737802 is a reply to message #1737786] Wed, 13 July 2016 07:03 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Test bundles, fragments and features can be pom-less. You only need pom files for target platform and product projects.

http://blog.vogella.com/2015/12/15/pom-less-tycho-builds-for-structured-environments/

The question is on how the test runtime is set up. Tycho Surefire takes the bundle under test and its dependencies to the test runtime. If the bundle under test has the import package statement things should work. Without it the bundle that contains your jar is not added to the test runtime.

I have written a blog post about testing declarative services. There are also some links included that lead to other solutions that describe how to add implicit dependencies to the test runtime.
http://blog.vogella.com/2016/07/04/osgi-component-testing/

Note that if you need additional settings for the tycho surefire test like explicitly add a test suite or command line args, you will need to have a pom file in the test fragment/bundle project, as pom-less tycho can not derive such special informations automatically.
Re: How to create and run JUnit tests on FX plugins? [message #1737810 is a reply to message #1737802] Wed, 13 July 2016 08:20 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Well the question then is how can tycho know that it needs to
reconfigure OSGi-Classloading?

I guess for OSGi-JavaFX apps pom-less can not work, right? Where does it
know if it needs to run
"org.eclipse.pde.junit.runtime.coretestapplication" with or without UI?

Tom


On 13.07.16 09:03, Dirk Fauth wrote:
> Test bundles, fragments and features can be pom-less. You only need pom
> files for target platform and product projects.
> http://blog.vogella.com/2015/12/15/pom-less-tycho-builds-for-structured-environments/
>
>
> The question is on how the test runtime is set up. Tycho Surefire takes
> the bundle under test and its dependencies to the test runtime. If the
> bundle under test has the import package statement things should work.
> Without it the bundle that contains your jar is not added to the test
> runtime.
>
> I have written a blog post about testing declarative services. There are
> also some links included that lead to other solutions that describe how
> to add implicit dependencies to the test runtime.
> http://blog.vogella.com/2016/07/04/osgi-component-testing/
>
> Note that if you need additional settings for the tycho surefire test
> like explicitly add a test suite or command line args, you will need to
> have a pom file in the test fragment/bundle project, as pom-less tycho
> can not derive such special informations automatically.
Re: How to create and run JUnit tests on FX plugins? [message #1737813 is a reply to message #1737810] Wed, 13 July 2016 08:29 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
AFAIK Tycho Surefire with pom-less Tycho will run JUnit Plug-in Tests in headless mode. So I guess your statement is correct that pom-less is not possible for testing OSGi-JavaFX applications, because of the -Dorg.osgi.framework.bundle.parent=ext argument.
Also if you want to execute UI tests you will need to provide a pom.xml for the corresponding configuration. But that is also the case for SWT UI tests.
Re: How to create and run JUnit tests on FX plugins? [message #1737857 is a reply to message #1737813] Wed, 13 July 2016 14:30 Go to previous message
John Bodkin is currently offline John BodkinFriend
Messages: 39
Registered: November 2011
Member
I added this to my config pom and the test project runs the test without having to create a POM file for the test project:
<plugin>
  <groupId>org.eclipse.tycho</groupId>
  <artifactId>tycho-surefire-plugin</artifactId>
  <version>${tycho.version}</version>
  <configuration>
    <useUIHarness>false</useUIHarness>
    <useUIThread>false</useUIThread>
    <argLine>-Dorg.osgi.framework.bundle.parent=ext</argLine>
    <appArgLine>-consoleLog -nosplash</appArgLine>
    <application>org.eclipse.pde.junit.runtime.coretestapplication</application>
  </configuration>
</plugin>


Thanks for all the responses. I would not have been able to do it without you.

[Updated on: Wed, 13 July 2016 14:30]

Report message to a moderator

Previous Topic:@Preference - check if value exists
Next Topic:Junit Test fails for JavaFX nodes
Goto Forum:
  


Current Time: Fri Apr 19 16:52:21 GMT 2024

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

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

Back to the top