Tuesday, April 23, 2013

Surefire doesn't run the product/application specified

The product or application specified in configuration section of surefire are most probably on another bundle.
  1. Add the bundle as dependency to the plugin (in MANIFEST.MF) for which you have written the surefire configuration.
  2. Also add org.eclipse.equinox.ds if you have declared the product/application through extension points.

Now your test plugin should be able to access the application/product.

In case you have the extension points and tests in the same plugin/bundle you still have to do 2nd step.

Arguments needed to VM and program for running SWTBot tests with tycho surefire

When you use SWTBot widget finder to get widget with label or title, language comes into the game!
If the application is run with another language in another environment it's bound to fail.

You might think about externalizing/internationalizing your test cases. Is it worth it? ....

Unless you go for i18n you can specify the language as a program argument in surefire configuration

<appArgLine>-ln en</appArgLine> <!--for english-->

As you resolve target platform through tycho you might get out of memory from jvm in projects with enough library dependency.
Specify memory heap in surefire configuration.
<argLine>JVM heap size</argLine>

Specify the arch bootloader constant. why?



Maven doesn't find source in eclipse bundle to compile

By default maven thinks the java packages are in src/main/java/ directory relative to pom.xml location.
But usually eclipse bundle/plugin developers pur packages in src directory.

You can specify the source directory in maven a below
<project>
...
  <build>
    <sourceDirectory>${basedir}/src</sourceDirectory>
  </build>
...
</project>


Monday, April 22, 2013

stitch eclipse + swt + swtbot + junit + maven + tycho + surefire

In jist a high level view of running swtbot ui tests with maven/tycho
  1. Specify proper packaging i.e eclipse-test-plugin
  2. Specify src directory to maven build, usually it’s different in eclipse than what maven thinks
  3. Specify various parameters(memory, language, arch, ws, os, ..) correctly to vm and program
  4. Add necessary elements (UIHarness, UIThread…, application…) to tycho-surefire configuration
  5. Add all implicit dependencies of application/product as explicit to manifest file of the test plugin. Because tycho cannot resolve implicit dependencies.
  6. Add p2 repositories to pom so that target platform can be resolved into pom dependencies.
  7. Add Declarative Services library/ dependency to test plugin if it uses any declarative service to initialize application/product
All above steps assume at least mid level knowledge on maven/tycho/swtbot/eclipse/rcp and those who have tried the integration already.

32/64 bit issue with SWT, JVM. Solution maven way, eclipse way

SWT ships different libraries for each Operating System (os), Windowing System (ws) and Architecture (arch).
It doesn't allow loading 32 bit library into 64 bit JVM and vice versa.

So one should specify the osgi.arch value explicitly matching the jvm architecture.

In eclipse you can specify from launch configuration -> Arguments -> VM arguments
-Dosgi.arch=x86  for 32 bit jvm
-Dosgi.arch=x86_64 for 64 bit jvm

In maven there is more portable solution via profile
just activate correct profile on system sun.arch.data.model value

<project>
...
<profiles>
...
          <profile>
            <id>osgi-arch-64</id>
            <activation>
                <property>
                    <name>sun.arch.data.model</name>
                    <value>64</value>
                </property>
            </activation>
            <properties>
                <osgi.arch>x86_64</osgi.arch>
            </properties>
        </profile>
      
        <profile>
            <id>osgi-arch-32</id>
            <activation>
                <property>
                    <name>sun.arch.data.model</name>
                    <value>32</value>
                </property>
            </activation>
            <properties>
                <osgi.arch>x86</osgi.arch>
            </properties>
        </profile>
...
</profiles>
...
</project>

In case you are thinking why not setting -Dosgi.arch value in MAVEN_OPTS or JAVA_OPTS?

These are environment variables and they have to be set everywhere you build your project, all your teammates, build servers...