tralala
tralala

Reputation: 163

Manifest.mf cannot find org.junit

I'm trying to run jUnit tests for an Eclipse RCP application with Tycho.

For that I created a simple jUnit test, that runs when I click on Run as > jUnit-Test. But when I want to run it with mvn test, it doesn't find jUnit.

I read in the Internet that I have to add jUnit to the Build-Path. -> I already did that. Furthermore I read that I have to add jUnit as a require-bundle in my Manifest.mf file. But there is the problem!! I get the error: Bundle 'org.junit' canot be resolved.

My MANIFEST.MF file looks like this:

    Manifest-Version: 1.0
    Bundle-ManifestVersion: 2
    Bundle-Name: Tests
    Bundle-SymbolicName: myPackageName
    Bundle-Version: 1.0.0.qualifier
    Bundle-Vendor: myCompany
    Fragment-Host: thePackageWhereTestesPluginIs
    Bundle-RequiredExecutionEnvironment: JavaSE-1.6
    Require-Bundle: org.junit

Where is my mistake? When I take org.junit4 it cannot be resolved either...

Thank you!

Update:

Now I use instead of require-bundle:

    Import-package: org.junit4

(or org.junit, its' behavior is the same) and it can be resolved in the manifest.mf file. But when I run it, I get the following error: [ERROR] -> [Help 1] org.apache.maven.InternalErrorException: Internal error: java.lang.RuntimeException: org.osgi.framework.BundleException: Bundle myTestBundle cannot be resolved Resolution errors: Bundle myTestBundle - Missing Constraint: Import-Package: org.junit4; version="0.0.0"

How can I solve this?

Thank you!!

My pom file of the test bundle:

<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">    <modelVersion>4.0.0</modelVersion>
<parent>
        <artifactId>myProject.tycho.master</artifactId>
        <groupId>myProject</groupId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../myProject.tycho.master/pom.xml</relativePath>
    </parent>
    <groupId>myProject</groupId>
    <artifactId>myProject.myTestBundle</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>eclipse-test-plugin</packaging>

<dependencies>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.8.1</version>
</dependency>
</dependencies>
</project>

The parent pom:

    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<modelVersion>4.0.0</modelVersion>
<groupId>myProject</groupId>
<artifactId>myProject.tycho.master</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
    <tycho.version>0.17.0</tycho.version>
</properties>

<modules>
    <module>../myProject.myTestBundle</module>

</modules>



<repositories>
    <!-- configure p2 repository to resolve against -->
    <repository>
        <id>Repository1</id>
        <layout>p2</layout>
        <url>url-to-a-p2-site-on-my-server</url>
    </repository>
</repositories>

<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-maven-plugin</artifactId>
            <version>${tycho.version}</version>
            <extensions>true</extensions>
        </plugin>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>target-platform-configuration</artifactId>
            <version>${tycho.version}</version>
            <configuration>
                <resolver>p2</resolver>
                <pomDependencies>consider</pomDependencies>
                <target>
                    <artifact>
                        <groupId>myGroupId</groupId>
                        <artifactId>myGroupId.target</artifactId>
                        <classifier>targetPlatform</classifier>
                    </artifact>
                </target>
                <environments>
                    <environment>
                        <os>macosx</os>
                        <ws>cocoa</ws>
                        <arch>x86_64</arch>
                    </environment>
                    <environment>
                        <os>linux</os>
                        <ws>gtk</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>linux</os>
                        <ws>gtk</ws>
                        <arch>x86_64</arch>
                    </environment>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86_64</arch>
                    </environment>
                </environments>
                <ignoreTychoRepositories>false</ignoreTychoRepositories>
            </configuration>
        </plugin>
    </plugins>
</build>
    </project>

Update: I think I resolved the problem! I added jUnit to my p2 Update sites and now I don't get any errors!

Upvotes: 2

Views: 3740

Answers (1)

tralala
tralala

Reputation: 163

I fixed my problem by adding jUnit as a p2 Update site and used it in the Manifest.mf as:

Require-Bundle: org.junit; bundle-version = "4.11.0"

Upvotes: 1

Related Questions