Does anyone test e(fx)clipse applications? [message #1763909] |
Mon, 22 May 2017 19:19  |
Eclipse User |
|
|
|
Hi community,
I am wondering if anyone has run unit, functional and integration tests on e(fx)clipse applications and can comment on what the best approach is.
After some research in the Internet, I found that many people recommend writing test code using fragments for each plugin in e4 applications. Is this the recommended way for e(fx)clipse too? According to what I read, this approach is limited to JUnit 3.X tests or JUnit 4.x if one creates and maintains the test suites (I want to believe there is something better).
Also, what is the best way to launch and shutdown the whole application to perform functional and integration tests from the test class?
Since testing is a must in my case, I am giving a shot to the gradle Goomph plugin to try to run Tom's maven example using gradle. That would be the dream scenario for me because of how easily all kind of tests can run under gradle.
I requested some help from one of Goomph's programmers (Ned Twigg) and I would happily post here a working example if I ever get that far. If anyone is interested, the question thread is here: https://github.com/diffplug/goomph/issues/31
Thanks!
|
|
|
Re: Does anyone test e(fx)clipse applications? [message #1763939 is a reply to message #1763909] |
Tue, 23 May 2017 08:46   |
Eclipse User |
|
|
|
Well in our commerical application we:
* use MVVM and test those parts with simple JUnit-Tests because
* use TextFX for simple JUnit-Testing parts of the UI (if you follow our adviced component-structure each component can be started without OSGi and the e4 framework)
* use TestFX for integration tests (unfortunately publishing TextFX support at Eclipse.org is not going to happen because of license problems)
|
|
|
Re: Does anyone test e(fx)clipse applications? [message #1763941 is a reply to message #1763939] |
Tue, 23 May 2017 08:57   |
Eclipse User |
|
|
|
I'm not sure goomph will be of much help for you, point 1 & 2 should get you quite far already by leveraging standard testing infrastructure. To make 3 working with TestFX you need to make JUnit launch the OSGi-Application for you. I hope we can allocate some time in the 4.0 timeframe to streamline support to ease JUnit-Testing.
|
|
|
Re: Does anyone test e(fx)clipse applications? [message #1763978 is a reply to message #1763941] |
Tue, 23 May 2017 14:33   |
Eclipse User |
|
|
|
Thanks for your answer Tom. You were right regarding Goomph. So far I could not find a way to lauch e(fx)clispe with it.
I still have a few doubts:
How do you organize your tests in those commercial applications? Do you put the unit tests in the same plugin or you use fragments for them? What about the integration tests? Do you have a separate plugin or fragment for them? Is there something considered a best practice that make testing e(fx)clispe applications easier?
Lastly, how do you make JUnit launch the OSGi-Application for testing?
Thanks!
|
|
|
Re: Does anyone test e(fx)clipse applications? [message #1769023 is a reply to message #1763939] |
Tue, 25 July 2017 19:03   |
Eclipse User |
|
|
|
Could anyone please post pom.xml files that illustrate the configuration of test fragments both for simple JUnit tests and TestFX tests?
I managed to run simple JUnit tests using a test fragement but it does not work under maven... I would like to see examples of those files to find out what I am doing wrong...
Thanks!
|
|
|
|
Re: Does anyone test e(fx)clipse applications? [message #1769132 is a reply to message #1769047] |
Wed, 26 July 2017 22:55   |
Eclipse User |
|
|
|
@Dirk
Sorry for the late reply. I was aware of your tutorials and I was able to rest a project when JavaFX is not involved.
My current setup is extremely simple, since I want to figure out how to actually make test work. Starting with the template for creating a new e4 e(fx)clipse project, I added a plugin project with a simple class:
class Actor {
private StringProperty nameProperty = new SimpleStringProperty("Actor!");
String getName() {
return nameProperty.get();
}
}
and a fragment project for tests with the following class:
public class ActorTest {
@Test
public void testGetName() {
Actor actor = new Actor();
assertNotNull(actor.getName());
}
}
both projects have a pom.xml pointing to the app.releng project.
If instead of using the SimpleStringProperty I use a hard-coded string, everything works. When using a JavaFX 8 class, then the test fails with:
java.lang.NoClassDefFoundError: javafx/beans/property/StringProperty
My expectation is that a e(fx)clispe project created with a template should provide all the configuration for testing JavaFX classes.
The launch file has -Dorg.osgi.framework.bundle.parent=ext as a VM argument. So I don't know what I'm missing.
I noticed the template created a pom.xml for the releng project with the following content under pluginManagement->Plugins->Tycho
...
<extraClasspathElements>
<extraClasspathElement>
<groupId>javafx</groupId>
<artifactId>javafx.mvn</artifactId>
<version>2.2.0-SNAPSHOT</version>
</extraClasspathElement>
</extraClasspathElements>
...
Could that version (2.2.0-SNAPSHOT) be the problem?
Thanks
|
|
|
|
|
|
Re: Does anyone test e(fx)clipse applications? [message #1769234 is a reply to message #1769227] |
Fri, 28 July 2017 06:35   |
Eclipse User |
|
|
|
the following needs to go in your pom.xml
<build>
<resources>
<resource>
<directory>.</directory>
<includes>
<include>META-INF/</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<argLine>-Dorg.osgi.framework.bundle.parent=ext</argLine>
</configuration>
</plugin>
</plugins>
</build>
|
|
|
Re: Does anyone test e(fx)clipse applications? [message #1769286 is a reply to message #1769234] |
Fri, 28 July 2017 15:35   |
Eclipse User |
|
|
|
@Dirk
Thanks for the information. I have seen a video (I can't remember which one right now) that recommended using tycho surefire only for UI tests and use maven surefire for the rest. They were claiming performance reasons in a CI environment. I have no idea if that suggestion is relevant for e(fx)clipse projects. I might give it a try after I get a basic project properly setup. Now I need to dig into TestFX and how to configure the project to be tested with it... fun times ahead...
Thanks for taking the time to answer me. I really appreciate it.
@Tom
Thanks for your post. I tried adding that to the test fragment's pom.xml and it works with maven now.
Is there a chance you could blog about the different test setups (for Unit, TestFX for parts of the UI and integration tests using TestFX) until we have a reference project?
There are tons of useful information there and I think this topic will be a nice one to add to your collection. On top of that, if anyone trying to learn this topics try to find the information by its own, s/he will have a hard time and might be discouraged to use e(fx)clipse to develop anything meaningful.
You mentioned you use Model-View-ViewModel to setup your projects. Have you also tried PresentationModel-View-Controller? This last pattern is the one I used when working on a Griffon application and made testing easier. Griffon also provides the magic that synchronizes the presentation model and the view using the right threads, so users never have to worry about threading problems with the UI. It's quite cool.
Anyway, thanks again for your help. I have been struggling with this for quite some time now. I am kind of surprised that nobody seems to be testing e(fx)clipse applications...
|
|
|
|
Re: Does anyone test e(fx)clipse applications? [message #1769381 is a reply to message #1769303] |
Mon, 31 July 2017 08:14   |
Eclipse User |
|
|
|
Unfortunately the tests for OSGi-Applications interfere often with those simple standard tests :-( It looks like tests are run before the first ones are finished! I'm not sure who is to blame but I guess because of all the licensing shit around TestFX and Eclipse.org projects we need to roll our own test framework.
|
|
|
|
|
Re: Does anyone test e(fx)clipse applications? [message #1770517 is a reply to message #1770071] |
Sun, 13 August 2017 18:48   |
Eclipse User |
|
|
|
@Tom
Could you please tell me how to add FX-Test to my project?
I copied and pasted the pom.xml you show in the github repository in my test project (updating my project name).
I then tried to create the test extending but Eclipse cannot resolve it.
Is there a P2 repository for the snapshot version of FX-Test that I need to use?
Thanks!
|
|
|
|
Re: Does anyone test e(fx)clipse applications? [message #1770522 is a reply to message #1770520] |
Sun, 13 August 2017 22:14   |
Eclipse User |
|
|
|
@Tom
Thank you for your answer. Would you mind telling me where to use that repository?
I tried under Help->Install New Software->Add and copied the link you provided, but eclipse can't find anything there...
I added it to my repositories section in my releng's pom.xml, but still nothing...
Could you please tell me what I'm doing wrong?
Thanks!
|
|
|
|
|
Re: Does anyone test e(fx)clipse applications? [message #1770609 is a reply to message #1770585] |
Tue, 15 August 2017 02:11   |
Eclipse User |
|
|
|
@Tom
I am trying Fx-Test. I know this is a work in progress. Are you open to suggestions/ideas/discussions? If so, where would be the best place?
Also, I am having trouble with Mockito. I added version 1.9.5 to the target definition, and also objenesis, but I does not work at all: it is unable to mock the class complaining it can only mock visible and non final classes (which is the case in my project). Mockito can't even mock a public non-final class with a public default constructor residing in the very same package of the test fragment...
The whole thing with Eclipse, adding dependencies to the target definition from P2 repositories and adding them also to pom.xml seems a nightmare to me... I can't wait to drop maven and P2 altogether and start building e(fx)clipse projects with gradle. :(
In the meantime, I would like to be able to use Mockito. Could you share how you setup Mockito in eclipse for your projects? I am not concern about the pom.xml dependency...
Thanks again!
[Updated on: Tue, 15 August 2017 04:57] by Moderator Report message to a moderator
|
|
|
|
Re: Does anyone test e(fx)clipse applications? [message #1770662 is a reply to message #1770631] |
Tue, 15 August 2017 20:19   |
Eclipse User |
|
|
|
@Tom
As always, thanks again for your answer!
I'm kind of puzzled by your second statement: "I'm not using [Mockito] because if you use the service and di approach there should never be a reason to mock something".
I am using the service and dependency injection approach. To unit test whatever I am programing I was used to mock the service, set in the tested class, and verify interactions.
For example, lets assume I have a controller that requires a service that is injected by Eclipse's DI framework. The interaction in the controller happen when the different "onSomething" methods are called. My approach was to test the controller without the UI, mock the service and set it into the controller via a simple setter, and call the "onSomething" methods when I run the tests, verifying the controller calls the expected methods in the expected order on the mocked server. In this way I test only code in the controller. Isn't this a valid reason to use mocks? If not, could you tell me how you test this scenario?
Thanks again!
|
|
|
|
Powered by
FUDForum. Page generated in 0.06426 seconds