我正在嘗試使用Tycho爲Eclipse RCP應用程序運行jUnit測試。Manifest.mf找不到org.junit
爲此我創建了一個簡單的jUnit測試,當我單擊Run as> jUnit-Test時運行。但是當我想用mvn測試運行它時,它找不到jUnit。
我在互聯網上讀到我必須將jUnit添加到Build-Path。 - >我已經這樣做了。此外,我讀了我必須在我的Manifest.mf文件中添加jUnit作爲require-bundle。但有問題!我得到錯誤:捆綁'org.junit'canot被解決。
我的MANIFEST.MF文件看起來像這樣:
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
哪裏是我的錯?當我把org.junit4它也不能解決...
謝謝!
更新:
現在我用的,而不是需要管束:
Import-package: org.junit4
(或org.junit,它的行爲是一樣的),它可以在MANIFEST.MF文件來解決。但是當我運行它時,出現以下錯誤: [錯誤] - > [Help 1] org.apache.maven.InternalErrorException:內部錯誤:java.lang.RuntimeException:org.osgi.framework.BundleException:Bundle myTestBundle無法解析 解決錯誤: 捆綁myTestBundle - 缺少約束:導入包:org.junit4; version =「0.0.0」
我該如何解決這個問題?
謝謝!該測試包的
我的POM文件:
<?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>
父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>
更新: 我想我解決了這個問題! 我將jUnit添加到我的p2更新站點,現在我沒有得到任何錯誤!
你能後的POM文件,因爲我認爲你錯過了加在JUnit依賴你的pom文件。 – khmarbaise
現在我加了,謝謝你的幫助! – tralala
Tycho應該打印出更好的錯誤消息:https://bugs.eclipse.org/bugs/show_bug.cgi?id = 405790 – oberlies