Tycho with JUnit - How?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Tycho with JUnit - How?

Hansen Candrawinata
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.

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?

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.
~ Type the project name as "<eclipse-plugin-to-test>.tests" (good practice?).
~ Change the source folder to follow Maven convention "src/main/java".
~ Change the source folder to follow Maven convention "target/classes".
~ 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>

~ 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?
~ 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'.


Thanks,
Hansen
Reply | Threaded
Open this post in threaded view
|

Re: Tycho with JUnit - How?

Igor Fedorenko-3
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


Reply | Threaded
Open this post in threaded view
|

Re: Tycho with JUnit - How?

Hansen Candrawinata
Hi Igor,

Thanks for the reply.  It really helped me to understand more how Tycho works.  I still, however,  found some problems (see below).

Thanks!
Hansen


I decided to follow the Eclipse convention to have a separate test bundle for test classes.  I have three modules declared in my root pom.xml:
* core (the host plugin).
* core.tests (fragment bundling test classes for the host plugin).
* third-party-test (eclipse plugin containing third party jars such as junit; core.tests is dependent upon this plugin).

However, I encountered the following exception when running "mvn integration-test -DtestSuffix=.tests -e".  What could the cause be?

Error stacktrace:
org.apache.maven.lifecycle.LifecycleExecutionException: Internal error in the plugin manager executing goal 'org.codehaus.tycho:maven-osgi-test-plugin:0.3.0-DEV-1819:test': Mojo execution failed.
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:528)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:288)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:214)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:172)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:218)
        at org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:899)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:176)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:63)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:408)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:351)
Caused by: org.apache.maven.plugin.PluginExecutionException: Mojo execution failed.
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:645)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:521)
        ... 15 more
Caused by: org.apache.maven.plugin.MojoExecutionException: Could not determine test framework used by test bundle pac_core.tests_1.0.0.qualifier
        at org.codehaus.tycho.osgitest.TestMojo.getTestFramework(TestMojo.java:311)
        at org.codehaus.tycho.osgitest.TestMojo.execute(TestMojo.java:218)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:623)
        ... 16 more


Furthermore, I got the an NPE when I ran "mvn integration-test -DtestSuffix=.tests -DtestSuite=pac_core.configuration -DtestClass=pac_core.configuration.AllTests -e".  Sorry, I could not find any explanations on what -DtestSuite and -DtestClass should be, perhaps I specified the wrong values?  Does testSuite refer to my junit test suite class?  Does testClass refer to my junit test case class?

constituent[37]: file:/c:/Program%20Files/tycho-distribution-0.3.0-DEV-1819/lib/xercesMinimal-1.9.6.2.jar
---------------------------------------------------
java.lang.NullPointerException
        at org.codehaus.tycho.osgitools.OsgiStateController.getUserProperty(OsgiStateController.java:517)
        at org.codehaus.tycho.osgitools.OsgiStateController.getMavenProject(OsgiStateController.java:525)
        at org.codehaus.tycho.osgitest.TestMojo.execute(TestMojo.java:197)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:623)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:521)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:288)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:214)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:172)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:218)
        at org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:899)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:176)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:63)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:408)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:351)
Reply | Threaded
Open this post in threaded view
|

Re: Tycho with JUnit - How?

Igor Fedorenko-3
If you run "mvn integration-test", Tycho will find all unit tests in all
projects with packaging=eclipse-test-plugin in your build and run them.
Tycho assumes your test projects depend on either org.junit or
org.junit4 and uses different test runner depending on the junit version
used.

Error message "Could not determine test framework used by test bundle
pac_core.tests_1.0.0.qualifier" means that this project does not depend
on org.junit/org.junit4 and tycho does not know how to run it.

If you specify both -DtestSuite and -DtestClass, Tycho will run
specified test (suite) class only. testSuite is test bundle symbolic
name and testClass is fully qualified test class name. The NPE you see
is fixed in the latest Tycho DEV build (not officially declared, sorry)
and means that Tycho could not find Maven project that corresponds to
-DtestSuite=pac_core.configuration bundle symbolic name.

-DtestSuffix is only used when tycho generates pom.xml files for a set
of PDE projects. This property is ignored during actual build.

Hope this helps.

--
Regards,
Igor


Hansen Candrawinata wrote:

> Hi Igor,
>
> Thanks for the reply.  It really helped me to understand more how Tycho
> works.  I still, however,  found some problems (see below).
>
> Thanks!
> Hansen
>
>
> I decided to follow the Eclipse convention to have a separate test bundle
> for test classes.  I have three modules declared in my root pom.xml:
> * core (the host plugin).
> * core.tests (fragment bundling test classes for the host plugin).
> * third-party-test (eclipse plugin containing third party jars such as
> junit; core.tests is dependent upon this plugin).
>
> However, I encountered the following exception when running "mvn
> integration-test -DtestSuffix=.tests -e".  What could the cause be?
>
> Error stacktrace:
> org.apache.maven.lifecycle.LifecycleExecutionException: Internal error in
> the plugin manager executing goal
> 'org.codehaus.tycho:maven-osgi-test-plugin:0.3.0-DEV-1819:test': Mojo
> execution failed.
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:528)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:288)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:214)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:172)
>         at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:218)
>         at
> org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:899)
>         at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:176)
>         at org.apache.maven.cli.MavenCli.main(MavenCli.java:63)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at
> org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
>         at
> org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
>         at
> org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:408)
>         at
> org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:351)
> Caused by: org.apache.maven.plugin.PluginExecutionException: Mojo execution
> failed.
>         at
> org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:645)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:521)
>         ... 15 more
> Caused by: org.apache.maven.plugin.MojoExecutionException: Could not
> determine test framework used by test bundle pac_core.tests_1.0.0.qualifier
>         at
> org.codehaus.tycho.osgitest.TestMojo.getTestFramework(TestMojo.java:311)
>         at org.codehaus.tycho.osgitest.TestMojo.execute(TestMojo.java:218)
>         at
> org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:623)
>         ... 16 more
>
>
> Furthermore, I got the an NPE when I ran "mvn integration-test
> -DtestSuffix=.tests -DtestSuite=pac_core.configuration
> -DtestClass=pac_core.configuration.AllTests -e".  Sorry, I could not find
> any explanations on what -DtestSuite and -DtestClass should be, perhaps I
> specified the wrong values?  Does testSuite refer to my junit test suite
> class?  Does testClass refer to my junit test case class?
>
> constituent[37]:
> file:/c:/Program%20Files/tycho-distribution-0.3.0-DEV-1819/lib/xercesMinimal-1.9.6.2.jar
> ---------------------------------------------------
> java.lang.NullPointerException
>         at
> org.codehaus.tycho.osgitools.OsgiStateController.getUserProperty(OsgiStateController.java:517)
>         at
> org.codehaus.tycho.osgitools.OsgiStateController.getMavenProject(OsgiStateController.java:525)
>         at org.codehaus.tycho.osgitest.TestMojo.execute(TestMojo.java:197)
>         at
> org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:623)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:521)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:288)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:214)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:172)
>         at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:218)
>         at
> org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:899)
>         at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:176)
>         at org.apache.maven.cli.MavenCli.main(MavenCli.java:63)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at
> org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
>         at
> org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
>         at
> org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:408)
>         at
> org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:351)


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Tycho with JUnit - How?

Hansen Candrawinata
Hi Igor,

Sorry, I still could not get it to work.

Igor Fedorenko-4 wrote
Error message "Could not determine test framework used by test bundle
pac_core.tests_1.0.0.qualifier" means that this project does not depend
on org.junit/org.junit4 and tycho does not know how to run it.
I have actually declared a dependency to another plugin that contains junit libraries.  Here is the MANIFEST.MF of the project:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tests Fragment
Bundle-SymbolicName: pac_core.tests
Bundle-Version: 1.0.0
Fragment-Host: pac_core;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: pac_third_party_test;bundle-version="1.0.0"

pac_third_party_test contains the junit libraries.  Is this the right way to do it?  I could run the junit test case from within Eclipse, but not from CLI with Tycho.  I still always get the same exception "Caused by: org.apache.maven.plugin.MojoExecutionException: Could not determine test framework used by test bundle pac_core.tests_1.0.0".

I have also tried adding the junit.jar into the Bundle-ClassPath (Bundle-ClassPath: junit.jar), but this time another exception was thrown:

Error stacktrace:
org.apache.maven.ProjectBuildFailureException: Build for project: periodical:Bundle-SymbolicName:eclipse-test-plugin:1.0.0-SNAPSHOT failed during execution of mojo: org.codehaus.tycho:maven-osgi-compiler-plugin:0.3.0-DEV-1819:compile
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:316)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:214)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:172)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:218)
        at org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:899)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:176)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:63)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:408)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:351)
Caused by: org.codehaus.tycho.osgicompiler.copied.CompilationFailureException: Compilation failure
        at org.codehaus.tycho.osgicompiler.copied.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:404)
        at org.codehaus.tycho.osgicompiler.AbstractOsgiCompilerMojo.execute(AbstractOsgiCompilerMojo.java:107)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:623)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:521)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:288)
        ... 14 more
Reply | Threaded
Open this post in threaded view
|

Re: Tycho with JUnit - How?

Igor Fedorenko-3
Hansen,

Currently Tycho assumes that test projects have direct dependency on
either org.junit or org.junit4 bundles. This is probably too
restrictive, so feel free to enter enhancement request in JIRA [1].

In the mean time, you can add junit dependency directly to your test
project using something like


Require-Bundle: pac_third_party_test;bundle-version="1.0.0",org.junit


[1] http://jira.codehaus.org/browse/MNGECLIPSE


--
Regards,
Igor

Hansen Candrawinata wrote:

> Hi Igor,
>
> Sorry, I still could not get it to work.
>
>
> Igor Fedorenko-4 wrote:
>> Error message "Could not determine test framework used by test bundle
>> pac_core.tests_1.0.0.qualifier" means that this project does not depend
>> on org.junit/org.junit4 and tycho does not know how to run it.
>>
>
> I have actually declared a dependency to another plugin that contains junit
> libraries.  Here is the MANIFEST.MF of the project:
>
> Manifest-Version: 1.0
> Bundle-ManifestVersion: 2
> Bundle-Name: Tests Fragment
> Bundle-SymbolicName: pac_core.tests
> Bundle-Version: 1.0.0
> Fragment-Host: pac_core;bundle-version="1.0.0"
> Bundle-RequiredExecutionEnvironment: JavaSE-1.6
> Require-Bundle: pac_third_party_test;bundle-version="1.0.0"
>
> pac_third_party_test contains the junit libraries.  Is this the right way to
> do it?  I could run the junit test case from within Eclipse, but not from
> CLI with Tycho.  I still always get the same exception "Caused by:
> org.apache.maven.plugin.MojoExecutionException: Could not determine test
> framework used by test bundle pac_core.tests_1.0.0".
>
> I have also tried adding the junit.jar into the Bundle-ClassPath
> (Bundle-ClassPath: junit.jar), but this time another exception was thrown:
>
> Error stacktrace:
> org.apache.maven.ProjectBuildFailureException: Build for project:
> periodical:Bundle-SymbolicName:eclipse-test-plugin:1.0.0-SNAPSHOT failed
> during execution of mojo:
> org.codehaus.tycho:maven-osgi-compiler-plugin:0.3.0-DEV-1819:compile
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:316)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:214)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:172)
>         at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:218)
>         at
> org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:899)
>         at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:176)
>         at org.apache.maven.cli.MavenCli.main(MavenCli.java:63)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at
> org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
>         at
> org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
>         at
> org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:408)
>         at
> org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:351)
> Caused by:
> org.codehaus.tycho.osgicompiler.copied.CompilationFailureException:
> Compilation failure
>         at
> org.codehaus.tycho.osgicompiler.copied.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:404)
>         at
> org.codehaus.tycho.osgicompiler.AbstractOsgiCompilerMojo.execute(AbstractOsgiCompilerMojo.java:107)
>         at
> org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:623)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:521)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:288)
>         ... 14 more


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

RE: Tycho with JUnit - How?

Ulli Hafner-2
In reply to this post by Igor Fedorenko-3
> >
> > 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.
>

On the other hand, deploying the test cases in different plug-ins
has several drawbacks:

- Use can't test protected members.
- You won't see the code coverage (at least when using the eclipse
  test framework, I don't know how this is handled in tycho)

So we ended up to put unit tests into the same plug-in and use mvn
package assembly:assembly to strip of the unit tests from the jar.
(The only drawback is the remaining dependency of junit...)

Ulli

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Tycho with JUnit - How?

Hansen Candrawinata
In reply to this post by Igor Fedorenko-3
Igor Fedorenko-4 wrote
In the mean time, you can add junit dependency directly to your test
project using something like

Require-Bundle: pac_third_party_test;bundle-version="1.0.0",org.junit

Igor,

Thanks for replying.  But how do I get my test project to directly depend on org.junit?  As I said, the Eclipse plugin pac_third_party_test already contains the junit4 libraries, and my test project depends upon this plugin.  

Do I simply just change the pac_third_party_test's Bundle-SymbolicName name to org.junit and then change my test project to depend on org.junit instead of pac_third_party_test?  I tried this, and it initially seemed to work, but in the end it issued the message:

Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to c:\XXXXXX\pac-core.tests\target\surefire-reports for the individual test results.
        at org.codehaus.tycho.osgitest.TestMojo.execute(TestMojo.java:243)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:623)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:521)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:288)
        ... 14 more

But when I look into the target\surefire-reports directory, there were no test results - it's an empty directory.

Thanks,
Hansen
Reply | Threaded
Open this post in threaded view
|

Re: Tycho with JUnit - How?

Igor Fedorenko-3
Have a look at Tycho junit support integration test [1]. Make sure
target platform has org.junit bundles (all Eclipse SDKs have it) and run
the build using

$TYCHO_HOME/bin/mvn integration-test

from parent project folder.

[1]
http://svn.sonatype.org/m2eclipse/tycho/trunk/tycho-its/projects/TYCHO170

Hansen Candrawinata wrote:

>
> Igor Fedorenko-4 wrote:
>> In the mean time, you can add junit dependency directly to your test
>> project using something like
>>
>> Require-Bundle: pac_third_party_test;bundle-version="1.0.0",org.junit
>>
>
>
> Igor,
>
> Thanks for replying.  But how do I get my test project to directly depend on
> org.junit?  As I said, the Eclipse plugin pac_third_party_test already
> contains the junit4 libraries, and my test project depends upon this plugin.  
>
> Do I simply just change the pac_third_party_test's Bundle-SymbolicName name
> to org.junit and then change my test project to depend on org.junit instead
> of pac_third_party_test?  I tried this, and it initially seemed to work, but
> in the end it issued the message:
>
> Caused by: org.apache.maven.plugin.MojoFailureException: There are test
> failures.
>
> Please refer to c:\XXXXXX\pac-core.tests\target\surefire-reports for the
> individual test results.
>         at org.codehaus.tycho.osgitest.TestMojo.execute(TestMojo.java:243)
>         at
> org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:623)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:521)
>         at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:288)
>         ... 14 more
>
> But when I look into the target\surefire-reports directory, there were no
> test results - it's an empty directory.
>
> Thanks,
> Hansen


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Tycho with JUnit - How?

Hansen Candrawinata
In reply to this post by Hansen Candrawinata
Okay, so I get it to work now by changing the Bundle-SymbolicName name to org.junit and the version number to 3.8.0 (it was 1.0.0 before).  (is this the right way to do it, btw?)

Hmm, does this mean that somewhere in Tycho source code, it really expects "Bundle-SymbolicName.equals("org.junit") && Bundle-Version.equals("3.8.1")" to be true?  Hmmm, that does indeed sound too restrictive.  I'll see if I can file a request to improve this behaviour.

Hansen
Hansen Candrawinata wrote
Igor,

Thanks for replying.  But how do I get my test project to directly depend on org.junit?  As I said, the Eclipse plugin pac_third_party_test already contains the junit4 libraries, and my test project depends upon this plugin.  

Do I simply just change the pac_third_party_test's Bundle-SymbolicName name to org.junit and then change my test project to depend on org.junit instead of pac_third_party_test?  I tried this, and it initially seemed to work, but in the end it issued the message:

Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to c:\XXXXXX\pac-core.tests\target\surefire-reports for the individual test results.
        at org.codehaus.tycho.osgitest.TestMojo.execute(TestMojo.java:243)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:623)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:521)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:288)
        ... 14 more

But when I look into the target\surefire-reports directory, there were no test results - it's an empty directory.

Thanks,
Hansen
Reply | Threaded
Open this post in threaded view
|

Re: Tycho with JUnit - How?

Hansen Candrawinata
In reply to this post by Igor Fedorenko-3
Igor Fedorenko-4 wrote
Have a look at Tycho junit support integration test [1]. Make sure
target platform has org.junit bundles (all Eclipse SDKs have it)
Ok, so I think this is where the problem was.  My target platform does not have org.junit bundles.  Hmmm, okay.  That solves all the problems.

Thanks Igor.

PS. Please ignore my last question.  That shows how unwitting I was.