Hansen,
First, let me reiterate that our long term strategy is to support two
development workflows (or modes) in Tycho.
In "MANIFEST-first" mode, Tycho will use Eclipse and OSGi metadata and
rules to calculate project dependencies and other information needed
during the build. In this mode you should take any project that builds
and runs in PDE and build it on CLI with Tycho without much/any extra
configuration. This mode was (and still is) our primary focus.
In "POM-first" mode, Tycho will use Maven project configuration (i.e.
pom.xml) and rules to do the build. MANIFEST.MF and other Eclipse and
OSGi configuration files will be generated during the build based on
pom.xml. This mode has not been developed much yet but this may change soon.
See answers to your specific questions inline.
Hope this helps.
--
Regards,
Igor
Hansen Candrawinata wrote:
Hi,
Firstly, I am pretty new to Eclipse RCP applications and Tycho, so please
excuse my questions and lack of knowledge. I have also been reading some
(indirect) discussions about this, but still couldn't get a firm
understanding. I thought I would just post my questions here with the hope
that someone could answer them.
I have been using Tycho for about a month now, and it works really great. I
have successfully integrated it as a headless build tool for my RCP
application by following some previous discussions floating around here
(such as http://markmail.org/message/tzol62smonyqmag4).
My problem now is how to best use Tycho with JUnit.
1. My understanding is that normally test clases for an Eclipse plugin
should be separated into a separate test bundle. But why so? What are the
advantages of this over just placing them into a separate directory/test
package following the Maven convention? I read that the downside of
following Maven convention is that you will then need to include your test
code in your deployable plug-ins. But as I understand it, couldn't you just
use 'mvn package assembly:assembly' to build it to filter out the test
classes in the end? So it is not very clear to me as to why putting test
classes into a separate fragment is more beneficial in this case.
This is not Tycho specific, but rather how Eclipse/PDE JUnit support
works, so PDE newsgroup is probably a better place to get definitive
answer to why exactly this is the case. The way I understand it,
separating production and test code into individual plugins allows PDE
to use proper compile classpath with all dependencies and classpath
visibility configured the same way as at runtime.
2. If I want to follow the Maven convention (i.e. test classes under test
package), could I simply declare junit library as a dependency in my
pom.xml, as in the following?
<dependencyManagement>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>eclipse.org</groupId>
<artifactId>installation</artifactId>
<version>0.0.0</version>
<type>eclipse-installation</type>
<scope>system</scope>
<systemPath>${env.TYCHO_TARGET_PLATFORM}</systemPath>
</dependency>
<dependency>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>eclipse-plugin</type>
</dependency>
</dependencyManagement>
I tried this, and then ran 'mvn test', but Tycho/Maven does not seem to
compile my test classes. It just ignores them. Perhaps there is a specific
Tycho/Maven goal (that is, not 'mvn test') for this that I didn't know of?
Tyhco uses Eclipse and OSGi metadata and rules to calculate project
dependencies. You need to add Require-Bundle (or Import-Package) junit
dependency to MANIFEST.MF of your project.
3. If I want to follow the normal Eclipse convention (i.e. having a separate
test bundle for test classes), are the following steps correct (I could not
find any detailed step-by-step instructions to do this, so I came up with my
own, so please clarify if they are wrong)?
~ Create a fragment with the host plugin being the Eclipse plugin I want to
unit-test for.
It does not have to be a fragment. Regular bundle works too. You can
also x-friends MANIFEST.MF directive to make internal packages visible
to the test bundle only.
~ Type the project name as "<eclipse-plugin-to-test>.tests" (good
practice?).
This is just a convention, you can use other name if you want.
~ Change the source folder to follow Maven convention "src/main/java".
~ Change the source folder to follow Maven convention "target/classes".
You don't need to change source/target folders. Tycho uses
build.properties to find source folders.
~ Create a pom.xml file:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>some-group-id</groupId>
<artifactId>Bundle-SymbolicName</artifactId>
<version>Bundle-Version</version>
<packaging>eclipse-test-plugin</packaging>
</project>
Correct.
~ Declare a dependency to junit library. How do I do this? Is this a
pom.xml dependency or is this a MANIFEST.MF dependency? Or both?
Tycho uses MANIFEST.MF to determine project dependencies. Dependencies
declared in pom.xml are ignored.
~ Create a junit test class.
~ Go to command prompt, go to the fragment Eclipse test directory, and then
do 'mvn test' to run the test class created earlier.
~ Or go to the host Eclipse plugin directory, and then do 'mvn
integration-test -DtestSuffix=.tests'.
You need to build both project in the same reactor build (i.e. parent
pom with two modules) on CLI. In PDE, you can right-click on the test
project, then Run As->JUnit Plug-In Test.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email